Manages a view presentation for a control display surface.
Inheritance: GlobalId, IDisposable
Example #1
1
 /// <summary>
 /// Initialize a new instance of the ViewContext class.
 /// </summary>
 /// <param name="manager">Reference to the view manager.</param>
 /// <param name="control">Control associated with rendering.</param>
 /// <param name="alignControl">Control used for aligning elements.</param>
 /// <param name="renderer">Rendering provider.</param>
 public ViewContext(ViewManager manager,
                    Control control, 
                    Control alignControl, 
                    IRenderer renderer)
     : this(manager, control, alignControl, null, renderer)
 {
 }
Example #2
1
            public InternalListBox(KryptonListBox kryptonListBox)
            {
                SetStyle(ControlStyles.ResizeRedraw, true);

                _kryptonListBox = kryptonListBox;
                _mouseIndex = -1;

                // Create manager and view for drawing the background
                _drawPanel = new ViewDrawPanel();
                _viewManager = new ViewManager(this, _drawPanel);

                // Set required properties to act as an owner draw list box
                base.Size = Size.Empty;
                base.BorderStyle = BorderStyle.None;
                base.IntegralHeight = false;
                base.MultiColumn = false;
                base.DrawMode = DrawMode.OwnerDrawVariable;

                // We need to create and cache a device context compatible with the display
                _screenDC = PI.CreateCompatibleDC(IntPtr.Zero);
            }
Example #3
0
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator, 
									   ViewManager manager,
									   PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);

            // Get the current root element
            _oldRoot = ViewManager.Root;

            // Create a canvas for the border and background using current enabled state
            _drawCanvas = new ViewDrawCanvas(Navigator.StateNormal.HeaderGroup.Back,
                                             Navigator.StateNormal.HeaderGroup.Border,
                                             VisualOrientation.Top);

            // Put the exising root into the canvas
            _drawCanvas.Add(_oldRoot);

            // Set the correct palettes based on enabled state and selected page
            UpdateStatePalettes();

            // Canvas becomes the new root
            ViewManager.Root = _drawCanvas;

            // Need to monitor changes in the enabled state
            Navigator.EnabledChanged += new EventHandler(OnEnabledChanged);
        }
Example #4
0
        /// <summary>
        /// Initialize a new instance of the KryptonBorderEdge class.
        /// </summary>
        public KryptonBorderEdge()
        {
            // The label cannot take the focus
            SetStyle(ControlStyles.Selectable, false);

            // Set default label style
            _orientation = Orientation.Horizontal;

            // Create the palette storage
            _borderRedirect = new PaletteBorderInheritRedirect(Redirector, PaletteBorderStyle.ControlClient);
            _stateCommon = new PaletteBorderEdgeRedirect(_borderRedirect, NeedPaintDelegate);
            _stateDisabled = new PaletteBorderEdge(_stateCommon, NeedPaintDelegate);
            _stateNormal = new PaletteBorderEdge(_stateCommon, NeedPaintDelegate);
            _stateCurrent = _stateNormal;
            _state = PaletteState.Normal;

            // Our view contains just a simple canvas that covers entire client area
            _drawPanel = new ViewDrawPanel(_stateNormal);

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

            // We want to be auto sized by default, but not the property default!
            AutoSize = true;
            AutoSizeMode = AutoSizeMode.GrowAndShrink;
        }
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator, 
									   ViewManager manager,
									   PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);

            // Get the current root element
            _oldRoot = ViewManager.Root;

            // Create a canvas for the background
            _drawPanel = new ViewDrawPanel(Navigator.StateNormal.Back);

            // Put the exisint root into the canvas
            _drawPanel.Add(_oldRoot);

            // Update the child panel to have panel appearance
            Navigator.ChildPanel.PanelBackStyle = Navigator.Panel.PanelBackStyle;

            // Set the correct palettes based on enabled state and selected page
            UpdateStatePalettes();

            // Canvas becomes the new root
            ViewManager.Root = _drawPanel;

            // Need to monitor changes in the enabled state
            Navigator.EnabledChanged += new EventHandler(OnEnabledChanged);
        }
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator, 
									   ViewManager manager,
									   PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);
        }
Example #7
0
        /// <summary>
        /// Initialize a new instance of the KryptonGroup class.
        /// </summary>
        public KryptonGroup()
        {
            // Create the palette storage
            _stateCommon = new PaletteDoubleRedirect(Redirector, PaletteBackStyle.ControlClient, PaletteBorderStyle.ControlClient, NeedPaintDelegate);
            _stateDisabled = new PaletteDouble(_stateCommon, NeedPaintDelegate);
            _stateNormal = new PaletteDouble(_stateCommon, NeedPaintDelegate);

            // Create the internal panel used for containing content
            _panel = new KryptonGroupPanel(this, _stateCommon, _stateDisabled, _stateNormal, new NeedPaintHandler(OnGroupPanelPaint));

            // Make sure the panel back style always mimics our back style
            _panel.PanelBackStyle = PaletteBackStyle.ControlClient;

            // Create the element that fills the remainder space and remembers fill rectange
            _layoutFill = new ViewLayoutFill(_panel);

            // Create view for the control border and background
            _drawDocker = new ViewDrawDocker(_stateNormal.Back, _stateNormal.Border);
            _drawDocker.Add(_layoutFill, ViewDockStyle.Fill);

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

            // We want to default to shrinking and growing (base class defaults to GrowOnly)
            AutoSizeMode = AutoSizeMode.GrowAndShrink;

            // Add panel to the controls collection
            ((KryptonReadOnlyControls)Controls).AddInternal(_panel);
        }
 /// <summary>
 /// Initialize a new instance of the ViewContext class.
 /// </summary>
 /// <param name="manager">Reference to the view manager.</param>
 /// <param name="control">Control associated with rendering.</param>
 /// <param name="alignControl">Control used for aligning elements.</param>
 /// <param name="renderer">Rendering provider.</param>
 /// <param name="displaySize">Display size.</param>
 public ViewLayoutContext(ViewManager manager,
                          Control control,
                          Control alignControl,
                          IRenderer renderer,
                          Size displaySize)
     : this(manager, control, alignControl, null, renderer, displaySize)
 {
 }
 /// <summary>
 /// Initialize a new instance of the ViewContext class.
 /// </summary>
 /// <param name="manager">Reference to the view manager.</param>
 /// <param name="form">Form associated with rendering.</param>
 /// <param name="formRect">Window rectangle for the Form.</param>
 /// <param name="renderer">Rendering provider.</param>
 public ViewLayoutContext(ViewManager manager,
                          Form form,
                          Rectangle formRect,
                          IRenderer renderer)
     : base(manager, form, form, null, renderer)
 {
     // The initial display rectangle is the provided size
     DisplayRectangle = new Rectangle(Point.Empty, formRect.Size);
 }
Example #10
0
        /// <summary>
        /// Initialize a new instance of the ViewContext class.
        /// </summary>
        /// <param name="manager">Reference to the view manager.</param>
        /// <param name="control">Control associated with rendering.</param>
        /// <param name="alignControl">Control used to align elements.</param>
        /// <param name="graphics">Graphics instance for drawing.</param>
        /// <param name="clipRect">Rectangle that needs rendering.</param>
        /// <param name="renderer">Rendering provider.</param>
        public RenderContext(ViewManager manager,
                             Control control, 
                             Control alignControl,
							 Graphics graphics,
                             Rectangle clipRect,
							 IRenderer renderer)
            : base(manager, control, alignControl, graphics, renderer)
        {
            _clipRect = clipRect;
        }
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator,
                                       ViewManager manager,
                                       PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);

            // Need to monitor changes in the enabled state
            Navigator.EnabledChanged += new EventHandler(OnEnabledChanged);
        }
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator,
                                       ViewManager manager,
                                       PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);

            // Setup the drag and drop handler
            CreateDragDrop();
        }
Example #13
0
        /// <summary>
        /// Initialize a new instance of the VisualPopup class.
        /// </summary>
        /// <param name="viewManager">View manager instance for managing view display.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="shadow">Does the popup need a shadow effect.</param>
        public VisualPopup(ViewManager viewManager,
                           IRenderer renderer,
                           bool shadow)
        {
            #region Default ControlStyle Values
            // Default style values for Control are:-
            //	True  - AllPaintingInWmPaint
            //	False - CacheText
            //	False - ContainerControl
            //	False - EnableNotifyMessage
            //	False - FixedHeight
            //	False - FixedWidth
            //	False - Opaque
            //	False - OptimizedDoubleBuffer
            //	False - ResizeRedraw
            //	False - Selectable
            //	True  - StandardClick
            //	True  - StandardDoubleClick
            //	False - SupportsTransparentBackColor
            //	False - UserMouse
            //	True  - UserPaint
            //	True  - UseTextForAccessibility
            #endregion

            // We use double buffering to reduce drawing flicker
            SetStyle(ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint, true);

            // We need to repaint entire control whenever resized
            SetStyle(ControlStyles.ResizeRedraw, true);

            // Cannot select control by using mouse to click it
            SetStyle(ControlStyles.Selectable, false);

            // Cache incoming references
            _renderer = renderer;
            _viewManager = viewManager;

            // Setup the need paint delegate
            _needPaintDelegate = new NeedPaintHandler(OnNeedPaint);

            // Setup the invokes
            _refreshCall = new SimpleCall(OnPerformRefresh);

            // Default other properties
            _layoutDirty = true;
            _refresh = true;

            // Create the shadow control
            if (shadow)
                _shadow = new VisualPopupShadow();
        }
        /// <summary>
        /// Initialize a new instance of the VisualPopupMinimized class.
        /// </summary>
        /// <param name="ribbon">Owning ribbon control instance.</param>
        /// <param name="viewManager">View manager instance for managing view display.</param>
        /// <param name="captionArea">View element that manages the custom chrome injection.</param>
        /// <param name="renderer">Drawing renderer.</param>
        public VisualPopupMinimized(KryptonRibbon ribbon,
                                    ViewManager viewManager,
                                    ViewDrawRibbonCaptionArea captionArea,
                                    IRenderer renderer)
            : base(viewManager, renderer, true)
        {
            Debug.Assert(ribbon != null);
            Debug.Assert(captionArea != null);

            // Remember incoming references
            _ribbon = ribbon;
            _captionArea = captionArea;
        }
Example #15
0
        /// <summary>
        /// Initialize a new instance of the ViewContext class.
        /// </summary>
        /// <param name="manager">Reference to the view manager.</param>
        /// <param name="control">Control associated with rendering.</param>
        /// <param name="alignControl">Control used for aligning elements.</param>
        /// <param name="graphics">Graphics instance for drawing.</param>
        /// <param name="renderer">Rendering provider.</param>
        public ViewContext(ViewManager manager,
                           Control control,
                           Control alignControl,
                           Graphics graphics,
						   IRenderer renderer)
        {
            // Use the manager is provided, otherwise create a temporary one with a null view
            if (manager != null)
                _manager = manager;
            else
            {
                _manager = new ViewManager(control, new ViewLayoutNull());
                _disposeManager = true;
            }

            // Cache initial values
            _control = control;
            _alignControl = alignControl;
            _graphics = graphics;
            _renderer = renderer;
        }
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator, 
									   ViewManager manager,
									   PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);

            // Get the current root element
            _oldRoot = ViewManager.Root;

            // Construct the viewlet instance
            _headerGroup = new ViewletHeaderGroup(navigator, redirector, NeedPaintDelegate);

            // Create and initialize all objects
            ViewBase newRoot = _headerGroup.Construct(_oldRoot);
            _headerGroup.PostCreate();

            // Assign the new root
            ViewManager.Root = newRoot;

            // Need to monitor changes in the enabled state
            Navigator.EnabledChanged += new EventHandler(OnEnabledChanged);
        }
        /// <summary>
        /// Construct the view appropriate for this builder.
        /// </summary>
        /// <param name="navigator">Reference to navigator instance.</param>
        /// <param name="manager">Reference to current manager.</param>
        /// <param name="redirector">Palette redirector.</param>
        public override void Construct(KryptonNavigator navigator, 
									   ViewManager manager,
									   PaletteRedirect redirector)
        {
            // Let base class perform common operations
            base.Construct(navigator, manager, redirector);

            // Get the current root element
            _oldRoot = ViewManager.Root;

            // Create and initialize all objects
            CreateCheckItemView();
            CreateButtonSpecManager();
            CreateNavCheckItems();
            UpdateCheckItemStyle();
            UpdateOrientation();
            UpdateStatePalettes();
            PostCreate();

            // Force buttons to be recreated in the headers
            if (_buttonManager != null)
                _buttonManager.RecreateButtons();

            // Canvas becomes the new root
            ViewManager.Root = _newRoot;

            // Need to monitor changes in the enabled state
            Navigator.EnabledChanged += new EventHandler(OnNavigatorEnabledChanged);
            Navigator.RightToLeftChanged += new EventHandler(OnNavigatorRightToLeftChanged);
        }
Example #18
0
        public KryptonListBox()
        {
            // Contains another control and needs marking as such for validation to work
            SetStyle(ControlStyles.ContainerControl, true);

            // Cannot select this control, only the child ListBox and does not generate a click event
            SetStyle(ControlStyles.Selectable | ControlStyles.StandardClick, false);

            // Default fields
            _alwaysActive = true;
            _lastSelectedIndex = -1;
            _style = ButtonStyle.ListItem;
            base.Padding = new Padding(1);

            // Create the palette storage
            _stateCommon = new PaletteListStateRedirect(Redirector, PaletteBackStyle.InputControlStandalone, PaletteBorderStyle.InputControlStandalone, NeedPaintDelegate);
            _stateFocus = new PaletteListItemTripleRedirect(Redirector, PaletteBackStyle.ButtonListItem, PaletteBorderStyle.ButtonListItem, PaletteContentStyle.ButtonListItem, NeedPaintDelegate);
            _stateDisabled = new PaletteListState(_stateCommon, NeedPaintDelegate);
            _stateActive = new PaletteDouble(_stateCommon, NeedPaintDelegate);
            _stateNormal = new PaletteListState(_stateCommon, NeedPaintDelegate);
            _stateTracking = new PaletteListItemTriple(_stateCommon.Item, NeedPaintDelegate);
            _statePressed = new PaletteListItemTriple(_stateCommon.Item, NeedPaintDelegate);
            _stateCheckedNormal = new PaletteListItemTriple(_stateCommon.Item, NeedPaintDelegate);
            _stateCheckedTracking = new PaletteListItemTriple(_stateCommon.Item, NeedPaintDelegate);
            _stateCheckedPressed = new PaletteListItemTriple(_stateCommon.Item, NeedPaintDelegate);

            // Create the override handling classes
            _overrideNormal = new PaletteTripleOverride(_stateFocus.Item, _stateNormal.Item, PaletteState.FocusOverride);
            _overrideTracking = new PaletteTripleOverride(_stateFocus.Item, _stateTracking.Item, PaletteState.FocusOverride);
            _overridePressed = new PaletteTripleOverride(_stateFocus.Item, _statePressed.Item, PaletteState.FocusOverride);
            _overrideCheckedNormal = new PaletteTripleOverride(_stateFocus.Item, _stateCheckedNormal.Item, PaletteState.FocusOverride);
            _overrideCheckedTracking = new PaletteTripleOverride(_stateFocus.Item, _stateCheckedTracking.Item, PaletteState.FocusOverride);
            _overrideCheckedPressed = new PaletteTripleOverride(_stateFocus.Item, _stateCheckedPressed.Item, PaletteState.FocusOverride);

            // Create the draw element for owner drawing individual items
            _contentValues = new FixedContentValue();
            _drawButton = new ViewDrawButton(StateDisabled.Item, _overrideNormal,
                                             _overrideTracking, _overridePressed,
                                             _overrideCheckedNormal, _overrideCheckedTracking,
                                             _overrideCheckedPressed,
                                             new PaletteMetricRedirect(Redirector),
                                             _contentValues, VisualOrientation.Top, false);

            // Create the internal list box used for containing content
            _listBox = new InternalListBox(this);
            _listBox.DrawItem += new DrawItemEventHandler(OnListBoxDrawItem);
            _listBox.MeasureItem += new MeasureItemEventHandler(OnListBoxMeasureItem);
            _listBox.TrackMouseEnter += new EventHandler(OnListBoxMouseChange);
            _listBox.TrackMouseLeave += new EventHandler(OnListBoxMouseChange);
            _listBox.DataSourceChanged += new EventHandler(OnListBoxDataSourceChanged);
            _listBox.DisplayMemberChanged += new EventHandler(OnListBoxDisplayMemberChanged);
            _listBox.ValueMemberChanged += new EventHandler(OnListBoxValueMemberChanged);
            _listBox.SelectedIndexChanged += new EventHandler(OnListBoxSelectedIndexChanged);
            _listBox.SelectedValueChanged += new EventHandler(OnListBoxSelectedValueChanged);
            _listBox.DisplayMemberChanged += new EventHandler(OnListBoxDisplayMemberChanged);
            _listBox.Format += new ListControlConvertEventHandler(OnListBoxFormat);
            _listBox.FormatInfoChanged += new EventHandler(OnListBoxFormatInfoChanged);
            _listBox.FormatStringChanged += new EventHandler(OnListBoxFormatStringChanged);
            _listBox.FormattingEnabledChanged += new EventHandler(OnListBoxFormattingEnabledChanged);
            _listBox.GotFocus += new EventHandler(OnListBoxGotFocus);
            _listBox.LostFocus += new EventHandler(OnListBoxLostFocus);
            _listBox.KeyDown += new KeyEventHandler(OnListBoxKeyDown);
            _listBox.KeyUp += new KeyEventHandler(OnListBoxKeyUp);
            _listBox.KeyPress += new KeyPressEventHandler(OnListBoxKeyPress);
            _listBox.PreviewKeyDown += new PreviewKeyDownEventHandler(OnListBoxPreviewKeyDown);
            _listBox.Validating += new CancelEventHandler(OnListBoxValidating);
            _listBox.Validated += new EventHandler(OnListBoxValidated);

            // Create the element that fills the remainder space and remembers fill rectange
            _layoutFill = new ViewLayoutFill(_listBox);
            _layoutFill.DisplayPadding = new Padding(1);

            // Create inner view for placing inside the drawing docker
            _drawDockerInner = new ViewLayoutDocker();
            _drawDockerInner.Add(_layoutFill, ViewDockStyle.Fill);

            // Create view for the control border and background
            _drawDockerOuter = new ViewDrawDocker(_stateNormal.Back, _stateNormal.Border);
            _drawDockerOuter.Add(_drawDockerInner, ViewDockStyle.Fill);

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

            // We need to create and cache a device context compatible with the display
            _screenDC = PI.CreateCompatibleDC(IntPtr.Zero);

            // Add list box to the controls collection
            ((KryptonReadOnlyControls)Controls).AddInternal(_listBox);
        }
        /// <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));
                }
            }
        }
        /// <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
            _labelValues = new LabelValues(NeedPaintDelegate);
            _labelValues.TextChanged += new EventHandler(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);
            _stateFocus = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate);

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

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

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

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

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

            // Need a controller for handling mouse input
            _controller = new CheckBoxController(_drawCheckBox, _layoutDocker, NeedPaintDelegate);
            _controller.Click += new EventHandler(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;
        }
Example #21
0
        /// <summary>
        /// Initialize a new instance of the KryptonDropButton class.
        /// </summary>
        public KryptonDropButton()
        {
            // 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;
            _useMnemonic = true;

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

            // Image need an extra redirector to check the local images first
            _paletteDropDownButtonImages = new PaletteRedirectDropDownButton(Redirector, Images);

            // 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,
                                             VisualOrientation.Top,
                                             UseMnemonic)
            {
                // Set default button state
                DropDown         = true,
                Splitter         = true,
                TestForFocusCues = true,
                DropDownPalette  = _paletteDropDownButtonImages
            };

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

            // 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);
        }
        /// <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);
        }
Example #23
0
        /// <summary>
        /// Use the setting from the Positioning to display the tooltip
        /// </summary>
        /// <param name="target"></param>
        /// <param name="controlMousePosition"></param>
        public void ShowRelativeTo(ViewBase target, Point controlMousePosition)
        {
            PopupPositionValues position;

            if (_contentValues is ToolTipValues toolTipValues)
            {
                position = toolTipValues.ToolTipPosition;
            }
            else
            {
                position = new PopupPositionValues();
            }
            Point currentCursorHotSpot = CommonHelper.CaptureCursor();

            Rectangle positionPlacementRectangle = position.PlacementRectangle;

            switch (position.PlacementMode)
            {
            case PlacementMode.Absolute:
            case PlacementMode.AbsolutePoint:
                // The screen, or PlacementRectangle if it is set.
                // So do nothing !
                break;

            case PlacementMode.Mouse:
            case PlacementMode.MousePoint:
                // The bounds of the mouse pointer. PlacementRectangle is ignored
                positionPlacementRectangle = new Rectangle(controlMousePosition.X, controlMousePosition.Y, currentCursorHotSpot.X + 2, currentCursorHotSpot.Y + 2);
                break;

            default:
                // The screen, or PlacementRectangle if it is set. The PlacementRectangle is relative to the screen.
                if (positionPlacementRectangle.IsEmpty)
                {
                    // PlacementTarget or parent.
                    positionPlacementRectangle =
                        position.PlacementTarget?.ClientRectangle ?? target.ClientRectangle;
                    positionPlacementRectangle = (position.PlacementTarget?.OwningControl ?? target.OwningControl).RectangleToScreen(positionPlacementRectangle);
                }
                else
                {
                    positionPlacementRectangle = Screen.GetWorkingArea(controlMousePosition);
                }
                break;
            }

            // Get the size the popup would like to be
            Size  popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty);
            Point popupLocation;

            switch (position.PlacementMode)
            {
            case PlacementMode.Absolute:
            case PlacementMode.AbsolutePoint:
            case PlacementMode.MousePoint:
            case PlacementMode.Relative:
            case PlacementMode.RelativePoint:
                // The top-left corner of the target area.     The top-left corner of the Popup.
                popupLocation = positionPlacementRectangle.Location;
                if (positionPlacementRectangle.IntersectsWith(new Rectangle(controlMousePosition, (Size)currentCursorHotSpot)))
                {
                    // TODO: SKC: Should really get the HotSpot from the Icon and use that !
                    popupLocation.X = controlMousePosition.X + 4;     // Still might "Bounce back" due to offscreen location
                }
                break;

            case PlacementMode.Bottom:
            case PlacementMode.Mouse:
                // The bottom-left corner of the target area.     The top-left corner of the Popup.
                popupLocation = new Point(positionPlacementRectangle.Left, positionPlacementRectangle.Bottom);
                break;

            case PlacementMode.Center:
                // The center of the target area.     The center of the Popup.
                popupLocation = positionPlacementRectangle.Location;
                popupLocation.Offset(popupSize.Width / 2, -popupSize.Height / 2);
                if (positionPlacementRectangle.IntersectsWith(new Rectangle(controlMousePosition, (Size)currentCursorHotSpot)))
                {
                    // TODO: SKC: Should really get the HotSpot from the Icon and use that !
                    popupLocation.X = controlMousePosition.X + 4;     // Still might "Bounce back" due to offscreen location
                }
                break;

            case PlacementMode.Left:
                // The top-left corner of the target area.     The top-right corner of the Popup.
                popupLocation = new Point(positionPlacementRectangle.Left - popupSize.Width, positionPlacementRectangle.Top);
                break;

            case PlacementMode.Right:
                // The top-right corner of the target area.     The top-left corner of the Popup.
                popupLocation = new Point(positionPlacementRectangle.Right, positionPlacementRectangle.Top);
                break;

            case PlacementMode.Top:
                // The top-left corner of the target area.     The bottom-left corner of the Popup.
                popupLocation = new Point(positionPlacementRectangle.Left, positionPlacementRectangle.Top - popupSize.Height);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            // Show it now!
            Show(popupLocation, popupSize);
        }
Example #24
0
        /// <summary>
        /// Initialize a new instance of the KryptonSeparator class.
        /// </summary>
        public KryptonSeparator()
        {
            // The label cannot take the focus
            SetStyle(ControlStyles.Selectable, false);

            // Create the palette storage
            _stateCommon = new PaletteSplitContainerRedirect(Redirector, PaletteBackStyle.PanelClient,
                                                             PaletteBorderStyle.ControlClient, PaletteBackStyle.SeparatorHighProfile,
                                                             PaletteBorderStyle.SeparatorHighProfile, NeedPaintDelegate);

            // Never draw the border around the background
            _stateCommon.BorderRedirect.OverrideBorderToFalse = true;

            _stateDisabled = new PaletteSplitContainer(_stateCommon, _stateCommon.Separator, _stateCommon.Separator, NeedPaintDelegate);
            _stateNormal = new PaletteSplitContainer(_stateCommon, _stateCommon.Separator, _stateCommon.Separator, NeedPaintDelegate);
            _stateTracking = new PaletteSeparatorPadding(_stateCommon.Separator, _stateCommon.Separator, NeedPaintDelegate);
            _statePressed = new PaletteSeparatorPadding(_stateCommon.Separator, _stateCommon.Separator, NeedPaintDelegate);

            // Our view contains just a simple canvas that covers entire client area and a separator view
            _drawSeparator = new ViewDrawSeparator(_stateDisabled.Separator, _stateNormal.Separator, _stateTracking, _statePressed,
                                                   _stateDisabled.Separator, _stateNormal.Separator, _stateTracking, _statePressed,
                                                    PaletteMetricPadding.SeparatorPaddingLowProfile, Orientation.Vertical);

            // Get the separator to fill the entire client area
            _drawDocker = new ViewDrawDocker(_stateNormal.Back, _stateNormal.Border);
            _drawDocker.IgnoreAllBorderAndPadding = true;
            _drawDocker.Add(_drawSeparator, ViewDockStyle.Fill);

            // Create a separator controller to handle separator style behaviour
            _separatorController = new SeparatorController(this, _drawSeparator, true, true, NeedPaintDelegate);

            // Assign the controller to the view element to treat as a separator
            _drawSeparator.MouseController = _separatorController;
            _drawSeparator.KeyController = _separatorController;
            _drawSeparator.SourceController = _separatorController;

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

            // Use timer to redraw after windows messages are processed
            _redrawTimer = new Timer();
            _redrawTimer.Interval = 1;
            _redrawTimer.Tick += new EventHandler(OnRedrawTick);

            // Set other internal starting values
            _style = SeparatorStyle.HighProfile;
            _orientation = Orientation.Vertical;
            _allowMove = true;
            _splitterIncrements = 1;
            _splitterWidth = 5;
        }
Example #25
0
        /// <summary>
        /// Initialize a new instance of the RadioButton class.
        /// </summary>
        public KryptonRadioButton()
        {
            // 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;
            _useMnemonic   = true;
            _autoCheck     = true;

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

            // Create palette redirector
            _paletteCommonRedirect    = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            _paletteRadioButtonImages = new PaletteRedirectRadioButton(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, Values, 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
            _drawRadioButton = new ViewDrawRadioButton(_paletteRadioButtonImages)
            {
                CheckState = _checked
            };
            _layoutCenter = new ViewLayoutCenter
            {
                _drawRadioButton
            };

            // 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 RadioButtonController(_drawRadioButton, _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;
        }
Example #26
0
        public KryptonTreeView()
        {
            // Contains another control and needs marking as such for validation to work
            SetStyle(ControlStyles.ContainerControl, true);

            // Cannot select this control, only the child tree view and does not generate a click event
            SetStyle(ControlStyles.Selectable | ControlStyles.StandardClick, false);

            // Default fields
            _alwaysActive = true;
            _style = ButtonStyle.ListItem;
            _itemHeightDefault = true;
            _plusMinusImages = new TreeViewImages();
            _checkBoxImages = new CheckBoxImages();
            base.Padding = new Padding(1);

            // Create the palette storage
            _redirectImages = new PaletteRedirectTreeView(Redirector, _plusMinusImages, _checkBoxImages);
            PaletteBackInheritRedirect backInherit = new PaletteBackInheritRedirect(Redirector, PaletteBackStyle.InputControlStandalone);
            PaletteBorderInheritRedirect borderInherit = new PaletteBorderInheritRedirect(Redirector, PaletteBorderStyle.InputControlStandalone);
            PaletteBackColor1 commonBack = new PaletteBackColor1(backInherit, NeedPaintDelegate);
            PaletteBorder commonBorder = new PaletteBorder(borderInherit, NeedPaintDelegate);
            _stateCommon = new PaletteTreeStateRedirect(Redirector, commonBack, backInherit, commonBorder, borderInherit, NeedPaintDelegate);

            PaletteBackColor1 disabledBack = new PaletteBackColor1(_stateCommon.PaletteBack, NeedPaintDelegate);
            PaletteBorder disabledBorder = new PaletteBorder(_stateCommon.PaletteBorder, NeedPaintDelegate);
            _stateDisabled = new PaletteTreeState(_stateCommon, disabledBack, disabledBorder, NeedPaintDelegate);

            PaletteBackColor1 normalBack = new PaletteBackColor1(_stateCommon.PaletteBack, NeedPaintDelegate);
            PaletteBorder normalBorder = new PaletteBorder(_stateCommon.PaletteBorder, NeedPaintDelegate);
            _stateNormal = new PaletteTreeState(_stateCommon, normalBack, normalBorder, NeedPaintDelegate);

            PaletteBackColor1 activeBack = new PaletteBackColor1(_stateCommon.PaletteBack, NeedPaintDelegate);
            PaletteBorder activeBorder = new PaletteBorder(_stateCommon.PaletteBorder, NeedPaintDelegate);
            _stateActive = new PaletteDouble(_stateCommon, activeBack, activeBorder, NeedPaintDelegate);

            _stateFocus = new PaletteTreeNodeTripleRedirect(Redirector, PaletteBackStyle.ButtonListItem, PaletteBorderStyle.ButtonListItem, PaletteContentStyle.ButtonListItem, NeedPaintDelegate);
            _stateTracking = new PaletteTreeNodeTriple(_stateCommon.Node, NeedPaintDelegate);
            _statePressed = new PaletteTreeNodeTriple(_stateCommon.Node, NeedPaintDelegate);
            _stateCheckedNormal = new PaletteTreeNodeTriple(_stateCommon.Node, NeedPaintDelegate);
            _stateCheckedTracking = new PaletteTreeNodeTriple(_stateCommon.Node, NeedPaintDelegate);
            _stateCheckedPressed = new PaletteTreeNodeTriple(_stateCommon.Node, NeedPaintDelegate);

            // Create the override handling classes
            _overrideNormal = new PaletteTripleOverride(_stateFocus.Node, _stateNormal.Node, PaletteState.FocusOverride);
            _overrideTracking = new PaletteTripleOverride(_stateFocus.Node, _stateTracking.Node, PaletteState.FocusOverride);
            _overridePressed = new PaletteTripleOverride(_stateFocus.Node, _statePressed.Node, PaletteState.FocusOverride);
            _overrideCheckedNormal = new PaletteTripleOverride(_stateFocus.Node, _stateCheckedNormal.Node, PaletteState.FocusOverride);
            _overrideCheckedTracking = new PaletteTripleOverride(_stateFocus.Node, _stateCheckedTracking.Node, PaletteState.FocusOverride);
            _overrideCheckedPressed = new PaletteTripleOverride(_stateFocus.Node, _stateCheckedPressed.Node, PaletteState.FocusOverride);
            _overrideNormalNode = new PaletteNodeOverride(_overrideNormal);

            // Create the check box image drawer and place inside element so it is always centered
            _drawCheckBox = new ViewDrawCheckBox(_redirectImages);
            _layoutCheckBox = new ViewLayoutCenter();
            _layoutCheckBox.Add(_drawCheckBox);

            // Stack used to layout the location of the node image
            _layoutImage = new ViewLayoutSeparator(0, 0);
            _layoutImageAfter = new ViewLayoutSeparator(3, 0);
            _layoutImageCenter = new ViewLayoutCenter(_layoutImage);
            _layoutImageStack = new ViewLayoutStack(true);
            _layoutImageStack.Add(_layoutImageCenter);
            _layoutImageStack.Add(_layoutImageAfter);
            _layoutImageState = new ViewLayoutSeparator(16, 16);
            _layoutImageCenterState = new ViewLayoutCenter(_layoutImageState);

            // Create the draw element for owner drawing individual items
            _contentValues = new FixedContentValue();
            _drawButton = new ViewDrawButton(StateDisabled.Node, _overrideNormalNode,
                                             _overrideTracking, _overridePressed,
                                             _overrideCheckedNormal, _overrideCheckedTracking,
                                             _overrideCheckedPressed,
                                             new PaletteMetricRedirect(Redirector),
                                             _contentValues, VisualOrientation.Top, false);

            // Place check box on the left and the label in the remainder
            _layoutDocker = new ViewLayoutDocker();
            _layoutDocker.Add(_layoutImageStack, ViewDockStyle.Left);
            _layoutDocker.Add(_layoutImageCenterState, ViewDockStyle.Left);
            _layoutDocker.Add(_layoutCheckBox, ViewDockStyle.Left);
            _layoutDocker.Add(_drawButton, ViewDockStyle.Fill);

            // Create the internal tree view used for containing content
            _treeView = new InternalTreeView(this);
            _treeView.TrackMouseEnter += new EventHandler(OnTreeViewMouseChange);
            _treeView.TrackMouseLeave += new EventHandler(OnTreeViewMouseChange);
            _treeView.GotFocus += new EventHandler(OnTreeViewGotFocus);
            _treeView.LostFocus += new EventHandler(OnTreeViewLostFocus);
            _treeView.KeyDown += new KeyEventHandler(OnTreeViewKeyDown);
            _treeView.KeyUp += new KeyEventHandler(OnTreeViewKeyUp);
            _treeView.KeyPress += new KeyPressEventHandler(OnTreeViewKeyPress);
            _treeView.PreviewKeyDown += new PreviewKeyDownEventHandler(OnTreeViewPreviewKeyDown);
            _treeView.Validating += new CancelEventHandler(OnTreeViewValidating);
            _treeView.Validated += new EventHandler(OnTreeViewValidated);
            _treeView.AfterCheck += new TreeViewEventHandler(OnTreeViewAfterCheck);
            _treeView.AfterCollapse += new TreeViewEventHandler(OnTreeViewAfterCollapse);
            _treeView.AfterExpand += new TreeViewEventHandler(OnTreeViewAfterExpand);
            _treeView.AfterLabelEdit += new NodeLabelEditEventHandler(OnTreeViewAfterLabelEdit);
            _treeView.AfterSelect += new TreeViewEventHandler(OnTreeViewAfterSelect);
            _treeView.BeforeCheck += new TreeViewCancelEventHandler(OnTreeViewBeforeCheck);
            _treeView.BeforeCollapse += new TreeViewCancelEventHandler(OnTreeViewBeforeCollapse);
            _treeView.BeforeExpand += new TreeViewCancelEventHandler(OnTreeViewBeforeExpand);
            _treeView.BeforeLabelEdit += new NodeLabelEditEventHandler(OnTreeViewBeforeLabelEdit);
            _treeView.BeforeSelect += new TreeViewCancelEventHandler(OnTreeViewBeforeSelect);
            _treeView.ItemDrag += new ItemDragEventHandler(OnTreeViewItemDrag);
            _treeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(OnTreeViewNodeMouseClick);
            _treeView.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(OnTreeViewNodeMouseDoubleClick);
            _treeView.NodeMouseHover += new TreeNodeMouseHoverEventHandler(OnTreeViewNodeMouseHover);
            _treeView.DrawNode += new DrawTreeNodeEventHandler(OnTreeViewDrawNode);
            _treeView.DrawMode = TreeViewDrawMode.OwnerDrawAll;

            // Create the element that fills the remainder space and remembers fill rectange
            _layoutFill = new ViewLayoutFill(_treeView);
            _layoutFill.DisplayPadding = new Padding(1);

            // Create inner view for placing inside the drawing docker
            _drawDockerInner = new ViewLayoutDocker();
            _drawDockerInner.Add(_layoutFill, ViewDockStyle.Fill);

            // Create view for the control border and background
            _drawDockerOuter = new ViewDrawDocker(_stateNormal.Back, _stateNormal.Border);
            _drawDockerOuter.Add(_drawDockerInner, ViewDockStyle.Fill);

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

            // We need to create and cache a device context compatible with the display
            _screenDC = PI.CreateCompatibleDC(IntPtr.Zero);

            // Add tree view to the controls collection
            ((KryptonReadOnlyControls)Controls).AddInternal(_treeView);
        }
        /// <summary>
        /// Initialize a new instance of the ViewContext class.
        /// </summary>
        /// <param name="manager">Reference to the view manager.</param>
        /// <param name="control">Control associated with rendering.</param>
        /// <param name="alignControl">Control used for aligning elements.</param>
        /// <param name="graphics">Graphics instance for drawing.</param>
        /// <param name="renderer">Rendering provider.</param>
        /// <param name="displaySize">Display size.</param>
        public ViewLayoutContext(ViewManager manager,
                                 Control control,
                                 Control alignControl,
                                 Graphics graphics,
								 IRenderer renderer,
                                 Size displaySize)
            : base(manager, control, alignControl, graphics, renderer)
        {
            // The initial display rectangle is the provided size
            DisplayRectangle = new Rectangle(Point.Empty, displaySize);
        }
Example #28
0
            public InternalTreeView(KryptonTreeView kryptonTreeView)
            {
                SetStyle(ControlStyles.ResizeRedraw, true);

                _kryptonTreeView = kryptonTreeView;

                // Create manager and view for drawing the background
                _drawPanel = new ViewDrawPanel();
                _viewManager = new ViewManager(this, _drawPanel);

                // Set required properties to act as an owner draw list box
                base.Size = Size.Empty;
                base.BorderStyle = BorderStyle.None;

                // We need to create and cache a device context compatible with the display
                _screenDC = PI.CreateCompatibleDC(IntPtr.Zero);
            }
        /// <summary>
        /// Initialize a new instance of the VisualPopupPage class.
        /// </summary>
        /// <param name="navigator">Reference to owning navigator control.</param>
        /// <param name="page">Reference to page for display.</param>
        /// <param name="renderer">Drawing renderer.</param>
        public VisualPopupPage(KryptonNavigator navigator,
                               KryptonPage page,
                               IRenderer renderer)
            : base(renderer, true)
        {
            Debug.Assert(navigator != null);
            Debug.Assert(page != null);

            // Remember references needed later
            _navigator = navigator;
            _page = page;

            // Always create the layout that positions the actual page
            ViewLayoutPopupPage layoutPage = new ViewLayoutPopupPage(navigator, page);

            // Create the internal panel used for containing content
            ViewDrawCanvas drawGroup = new ViewDrawCanvas(navigator.StateNormal.HeaderGroup.Back,
                                                          navigator.StateNormal.HeaderGroup.Border,
                                                          VisualOrientation.Top);

            // Add the layout inside the draw group
            drawGroup.Add(layoutPage);

            // Do we need to add a border area around the page group
            if (_navigator.PopupPages.Border > 0)
            {
                // Grab the actual border values
                int border = _navigator.PopupPages.Border;

                // Put the page group inside a layout that has separators
                // to pad out the sizing to the border size we need
                ViewLayoutDocker layoutDocker = new ViewLayoutDocker();
                layoutDocker.Add(drawGroup, ViewDockStyle.Fill);
                layoutDocker.Add(new ViewLayoutSeparator(border), ViewDockStyle.Top);
                layoutDocker.Add(new ViewLayoutSeparator(border), ViewDockStyle.Bottom);
                layoutDocker.Add(new ViewLayoutSeparator(border), ViewDockStyle.Left);
                layoutDocker.Add(new ViewLayoutSeparator(border), ViewDockStyle.Right);

                // Create a new top level group that contains the layout
                drawGroup = new ViewDrawCanvas(navigator.StateNormal.Back,
                                               navigator.StateNormal.HeaderGroup.Border,
                                               VisualOrientation.Top);

                drawGroup.Add(layoutDocker);
            }

            ViewManager = new ViewManager(this, drawGroup);

            // Borrow the child panel that contains all the pages from
            // the navigator and add it inside as a child of ourself
            navigator.BorrowChildPanel();
            Controls.Add(navigator.ChildPanel);
        }
        /// <summary>
        /// Initialize a new instance of the KryptonDropButton class.
        /// </summary>
        public KryptonDropButton()
        {
            // 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;
            _useMnemonic = true;

            // Create content storage
            _buttonValues = CreateButtonValues(NeedPaintDelegate);
            _buttonValues.TextChanged += new EventHandler(OnButtonTextChanged);
            _images = new DropDownButtonImages(NeedPaintDelegate);

            // Image need an extra redirector to check the local images first
            _paletteDropDownButtonImages = new PaletteRedirectDropDownButton(Redirector, _images);

            // 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);
            _stateDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);
            _stateFocus = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);

            // Create the override handling classes
            _overrideFocus = new PaletteTripleOverride(_stateFocus, _stateNormal,  PaletteState.FocusOverride);
            _overrideNormal = new PaletteTripleOverride(_stateDefault, _overrideFocus, PaletteState.NormalDefaultOverride);
            _overrideTracking = new PaletteTripleOverride(_stateFocus, _stateTracking, PaletteState.FocusOverride);
            _overridePressed = new PaletteTripleOverride(_stateFocus, _statePressed, PaletteState.FocusOverride);

            // Create the view button instance
            _drawButton = new ViewDrawButton(_stateDisabled,
                                             _overrideNormal,
                                             _overrideTracking,
                                             _overridePressed,
                                             new PaletteMetricRedirect(Redirector),
                                             this,
                                             VisualOrientation.Top,
                                             UseMnemonic);

            // Set default button state
            _drawButton.DropDown = true;
            _drawButton.Splitter = true;
            _drawButton.TestForFocusCues = true;
            _drawButton.DropDownPalette = _paletteDropDownButtonImages;

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

            // 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 += new MouseEventHandler(OnButtonClick);
            _buttonController.MouseSelect += new MouseEventHandler(OnButtonSelect);

            // Create the view manager instance
            ViewManager = new ViewManager(this, _drawButton);
        }
Example #31
0
        /// <summary>
        /// Initialize a new instance of the KryptonPage class.
        /// </summary>
        /// <param name="text">Initial text.</param>
        /// <param name="imageSmall">Initial small image.</param>
        /// <param name="uniqueName">Initial unique name.</param>
        public KryptonPage(string text, Image imageSmall, string uniqueName)
        {
            // Default properties
            Text = text;
            MinimumSize = new Size(50, 50);
            _textTitle = "Page Title";
            _textDescription = "Page Description";
            _toolTipTitle = "Page ToolTip";
            _toolTipBody = string.Empty;
            _toolTipImage = null;
            _toolTipStyle = LabelStyle.ToolTip;
            _toolTipImageTransparentColor = Color.Empty;
            _imageSmall = imageSmall;
            _setVisible = true;
            _autoHiddenSlideSize = new Size(200, 200);
            _uniqueName = (string.IsNullOrEmpty(uniqueName) ? CommonHelper.UniqueString : uniqueName);
            _flags.Flags = (int)(KryptonPageFlags.All);
            _flags.ClearFlags((int)KryptonPageFlags.PageInOverflowBarForOutlookMode);

            // Create delegates
            _needDisabledPaint = new NeedPaintHandler(OnNeedDisabledPaint);
            _needNormalPaint = new NeedPaintHandler(OnNeedNormalPaint);

            // Create redirector for inheriting from owning navigator
            _redirectNavigator = new PaletteRedirectDoubleMetric(Redirector);
            _redirectNavigatorPage = new PaletteRedirectDouble(Redirector);
            _redirectNavigatorHeaderGroup = new PaletteRedirectDoubleMetric(Redirector);
            _redirectNavigatorHeaderPrimary = new PaletteRedirectTripleMetric(Redirector);
            _redirectNavigatorHeaderSecondary = new PaletteRedirectTripleMetric(Redirector);
            _redirectNavigatorHeaderBar = new PaletteRedirectTripleMetric(Redirector);
            _redirectNavigatorHeaderOverflow = new PaletteRedirectTripleMetric(Redirector);
            _redirectNavigatorCheckButton = new PaletteRedirectTriple(Redirector);
            _redirectNavigatorOverflowButton = new PaletteRedirectTriple(Redirector);
            _redirectNavigatorMiniButton = new PaletteRedirectTriple(Redirector);
            _redirectNavigatorBar = new PaletteRedirectMetric(Redirector);
            _redirectNavigatorSeparator = new PaletteRedirectDoubleMetric(Redirector);
            _redirectNavigatorTab = new PaletteRedirectTriple(Redirector);
            _redirectNavigatorRibbonTab = new PaletteRedirectRibbonTabContent(Redirector);

            // Create the palette storage
            _stateCommon = new PaletteNavigatorRedirect(null,
                                                        _redirectNavigator,
                                                        _redirectNavigatorPage,
                                                        _redirectNavigatorHeaderGroup,
                                                        _redirectNavigatorHeaderPrimary,
                                                        _redirectNavigatorHeaderSecondary,
                                                        _redirectNavigatorHeaderBar,
                                                        _redirectNavigatorHeaderOverflow,
                                                        _redirectNavigatorCheckButton,
                                                        _redirectNavigatorOverflowButton,
                                                        _redirectNavigatorMiniButton,
                                                        _redirectNavigatorBar,
                                                        new PaletteRedirectBorder(Redirector),
                                                        _redirectNavigatorSeparator,
                                                        _redirectNavigatorTab,
                                                        _redirectNavigatorRibbonTab,
                                                        new PaletteRedirectRibbonGeneral(Redirector),
                                                        NeedPaintDelegate);

            _stateDisabled = new PaletteNavigator(_stateCommon, _needDisabledPaint);
            _stateNormal = new PaletteNavigator(_stateCommon, _needNormalPaint);
            _stateTracking = new PaletteNavigatorOtherEx(_stateCommon, _needNormalPaint);
            _statePressed = new PaletteNavigatorOtherEx(_stateCommon, _needNormalPaint);
            _stateSelected = new PaletteNavigatorOther(_stateCommon, _needNormalPaint);

            _stateFocus = new PaletteNavigatorOtherRedirect(_redirectNavigatorCheckButton,
                                                            _redirectNavigatorOverflowButton,
                                                            _redirectNavigatorMiniButton,
                                                            _redirectNavigatorTab,
                                                            _redirectNavigatorRibbonTab, _needNormalPaint);

            // Our view contains just a simple canvas that covers entire client area
            _drawPanel = new ViewDrawPanel(_stateNormal.Page);

            // Create page specific button spec storage
            _buttonSpecs = new PageButtonSpecCollection(this);

            // Create the view manager instance
            ViewManager = new ViewManager(this, _drawPanel);
        }
        /// <summary>
        /// Initialize a new instance of the KryptonColorButton class.
        /// </summary>
        public KryptonColorButton()
        {
            // We generate click events manually, suppress default
            // production of them by the base Control class
            SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick, false);

            // Set default color button properties
            _style = ButtonStyle.Standalone;
            _visibleThemes = true;
            _visibleStandard = true;
            _visibleRecent = true;
            _visibleNoColor = true;
            _visibleMoreColors = true;
            _autoRecentColors = true;
            _schemeThemes = ColorScheme.OfficeThemes;
            _schemeStandard = ColorScheme.OfficeStandard;
            _selectedRect = new Rectangle(0, 12, 16, 4);
            _selectedColor = Color.Red;
            _emptyBorderColor = Color.DarkGray;
            _dialogResult = DialogResult.None;
            _useMnemonic = true;
            _maxRecentColors = 10;
            _recentColors = new List<Color>();

            // Create the context menu items
            _kryptonContextMenu = new KryptonContextMenu();
            _separatorTheme = new KryptonContextMenuSeparator();
            _headingTheme = new KryptonContextMenuHeading("Theme Colors");
            _colorsTheme = new KryptonContextMenuColorColumns(ColorScheme.OfficeThemes);
            _separatorStandard = new KryptonContextMenuSeparator();
            _headingStandard = new KryptonContextMenuHeading("Standard Colors");
            _colorsStandard = new KryptonContextMenuColorColumns(ColorScheme.OfficeStandard);
            _separatorRecent = new KryptonContextMenuSeparator();
            _headingRecent = new KryptonContextMenuHeading("Recent Colors");
            _colorsRecent = new KryptonContextMenuColorColumns(ColorScheme.None);
            _separatorNoColor = new KryptonContextMenuSeparator();
            _itemNoColor = new KryptonContextMenuItem("&No Color", Properties.Resources.ButtonNoColor, new EventHandler(OnClickNoColor));
            _itemsNoColor = new KryptonContextMenuItems();
            _itemsNoColor.Items.Add(_itemNoColor);
            _separatorMoreColors = new KryptonContextMenuSeparator();
            _itemMoreColors = new KryptonContextMenuItem("&More Colors...", new EventHandler(OnClickMoreColors));
            _itemsMoreColors = new KryptonContextMenuItems();
            _itemsMoreColors.Items.Add(_itemMoreColors);
            _kryptonContextMenu.Items.AddRange(new KryptonContextMenuItemBase[] { _separatorTheme, _headingTheme, _colorsTheme,
                                                                                  _separatorStandard, _headingStandard, _colorsStandard,
                                                                                  _separatorRecent, _headingRecent, _colorsRecent,
                                                                                  _separatorNoColor, _itemsNoColor,
                                                                                  _separatorMoreColors, _itemsMoreColors});

            // Create content storage
            _buttonValues = CreateButtonValues(NeedPaintDelegate);
            _buttonValues.TextChanged += new EventHandler(OnButtonTextChanged);
            _images = new DropDownButtonImages(NeedPaintDelegate);

            // Image need an extra redirector to check the local images first
            _paletteDropDownButtonImages = new PaletteRedirectDropDownButton(Redirector, _images);

            // Create the palette storage
            _strings = new PaletteColorButtonStrings();
            _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);
            _stateDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);
            _stateFocus = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);

            // Create the override handling classes
            _overrideFocus = new PaletteTripleOverride(_stateFocus, _stateNormal,  PaletteState.FocusOverride);
            _overrideNormal = new PaletteTripleOverride(_stateDefault, _overrideFocus, PaletteState.NormalDefaultOverride);
            _overrideTracking = new PaletteTripleOverride(_stateFocus, _stateTracking, PaletteState.FocusOverride);
            _overridePressed = new PaletteTripleOverride(_stateFocus, _statePressed, PaletteState.FocusOverride);

            // Create the view color button instance
            _drawButton = new ViewDrawButton(_stateDisabled,
                                             _overrideNormal,
                                             _overrideTracking,
                                             _overridePressed,
                                             new PaletteMetricRedirect(Redirector),
                                             this,
                                             VisualOrientation.Top,
                                             UseMnemonic);

            // Set default color button state
            _drawButton.DropDown = true;
            _drawButton.Splitter = true;
            _drawButton.TestForFocusCues = true;
            _drawButton.DropDownPalette = _paletteDropDownButtonImages;

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

            // 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 += new MouseEventHandler(OnButtonClick);
            _buttonController.MouseSelect += new MouseEventHandler(OnButtonSelect);

            // Create the view manager instance
            ViewManager = new ViewManager(this, _drawButton);
        }
Example #33
0
        /// <summary>
        /// Initialize a new instance of the KryptonGallery class.
        /// </summary>
        public KryptonGallery()
        {
            // Defaults
            _mouseOver = false;
            _alwaysActive = true;
            _selectedIndex = -1;
            _trackingIndex = -1;
            _eventTrackingIndex = -1;
            _preferredItemSize = new Size(5, 1);
            _dropMaxItemWidth = 128;
            _dropMinItemWidth = 3;

            // Timer used to generate tracking change event
            _trackingEventTimer = new Timer();
            _trackingEventTimer.Interval = 120;
            _trackingEventTimer.Tick += new EventHandler(OnTrackingTick);

            // Create content storage
            _images = new GalleryImages(NeedPaintDelegate);
            _dropButtonRanges = new KryptonGalleryRangeCollection();

            // Create the palette storage
            _stateCommon = new PaletteGalleryRedirect(Redirector, NeedPaintDelegate);
            _stateNormal = new PaletteGalleryState(_stateCommon, NeedPaintDelegate);
            _stateDisabled = new PaletteGalleryState(_stateCommon, NeedPaintDelegate);
            _stateActive = new PaletteGalleryState(_stateCommon, NeedPaintDelegate);

            // Create and organize the buttons
            _buttonUp = new ViewDrawRibbonGalleryButton(Redirector, PaletteRelativeAlign.Near, PaletteRibbonGalleryButton.Up, _images, NeedPaintDelegate);
            _buttonDown = new ViewDrawRibbonGalleryButton(Redirector, PaletteRelativeAlign.Center, PaletteRibbonGalleryButton.Down, _images, NeedPaintDelegate);
            _buttonContext = new ViewDrawRibbonGalleryButton(Redirector, PaletteRelativeAlign.Far, PaletteRibbonGalleryButton.DropDown, _images, NeedPaintDelegate);
            _buttonsLayout = new ViewLayoutRibbonGalleryButtons();
            _buttonsLayout.Add(_buttonUp);
            _buttonsLayout.Add(_buttonDown);
            _buttonsLayout.Add(_buttonContext);

            // The draw layout that contains the actual selection images
            _backBorder = new PaletteGalleryBackBorder(_stateNormal);
            _drawDocker = new ViewDrawDocker(_backBorder, _backBorder);
            _drawItems = new ViewLayoutRibbonGalleryItems(Redirector, this, NeedPaintDelegate, _buttonUp, _buttonDown, _buttonContext);
            _drawDocker.Add(_drawItems, ViewDockStyle.Fill);

            // Top level layout view
            _layoutDocker = new ViewLayoutDocker();
            _layoutDocker.Add(_drawDocker, ViewDockStyle.Fill);
            _layoutDocker.Add(_buttonsLayout, ViewDockStyle.Right);

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

            // Check the control is licenced
            KryptonGalleryLicence.PerformLicenceChecking(this);

            // Set the default padding value
            base.Padding = new Padding(3);
        }
Example #34
0
        /// <summary>
        /// Dispose of resources.
        /// </summary>
        public void Dispose()
        {
            // Is there a graphics instance that might need disposed?
            if (_graphics != null)
            {
                // Only dispose if we created it
                if (_disposeGraphics)
                    _graphics.Dispose();

                _graphics = null;
            }

            // Is there a manager instance that might need disposed?
            if (_manager != null)
            {
                // Only dispose if we created it
                if (_disposeManager)
                    _manager.Dispose();

                _manager = null;
            }
        }
 public void KryptonResetCounters()
 {
     ViewManager.ResetCounters();
 }
Example #36
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));
            }

            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Space:
                // Only interested in enabled items
                if (_menuItem.ItemEnabled)
                {
                    // Do we press the item or show the sub menu?
                    if (!_menuItem.HasSubMenu)
                    {
                        PressMenuItem();
                    }
                    else
                    {
                        _menuItem.ShowSubMenu(true);
                    }
                }
                break;

            case Keys.Tab:
                ViewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                ViewManager.KeyHome();
                break;

            case Keys.End:
                ViewManager.KeyEnd();
                break;

            case Keys.Up:
                ViewManager.KeyUp();
                break;

            case Keys.Down:
                ViewManager.KeyDown();
                break;

            case Keys.Left:
                // We wrap if are the first context menu shown, rather than a sub menu showing
                if (ViewManager.KeyLeft(!_menuItem.HasParentMenu))
                {
                    // User tried to fall off the left edge, so dismiss ourself and let the
                    // keyboard access take us back to the owning context menu instance
                    _menuItem.DisposeContextMenu();
                }
                break;

            case Keys.Right:
                // If enabled and with a sub menu, then show the sub menu
                if (_menuItem.ItemEnabled && _menuItem.HasSubMenu)
                {
                    _menuItem.ShowSubMenu(true);
                }
                else
                {
                    ViewManager.KeyRight();
                }

                break;
            }
        }
Example #37
0
        private void Construct()
        {
            // Our view contains just a simple canvas that covers entire client area
            _drawPanel = new ViewDrawPanel(_stateNormal.Back);

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