576 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			576 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.ComponentModel;
 | 
						|
using System.Drawing;
 | 
						|
using System.Windows.Forms;
 | 
						|
using DevComponents.DotNetBar.SuperGrid.Style;
 | 
						|
 | 
						|
namespace DevComponents.DotNetBar.SuperGrid
 | 
						|
{
 | 
						|
    ///<summary>
 | 
						|
    /// GridButtonXEditControl
 | 
						|
    ///</summary>
 | 
						|
    [ToolboxItem(false)]
 | 
						|
    public class GridRadialMenuEditControl : RadialMenu, IGridCellEditControl
 | 
						|
    {
 | 
						|
        #region Private variables
 | 
						|
 | 
						|
        private GridCell _Cell;
 | 
						|
        private EditorPanel _EditorPanel;
 | 
						|
        private Bitmap _EditorCellBitmap;
 | 
						|
 | 
						|
        private bool _ValueChanged;
 | 
						|
        private bool _SuspendUpdate;
 | 
						|
 | 
						|
        private StretchBehavior _StretchBehavior = StretchBehavior.None;
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// GridRadialMenuEditControl
 | 
						|
        ///</summary>
 | 
						|
        public GridRadialMenuEditControl()
 | 
						|
        {
 | 
						|
            this.SetStyle(
 | 
						|
                ControlStyles.UserPaint |
 | 
						|
                ControlStyles.AllPaintingInWmPaint |
 | 
						|
                ControlStyles.Opaque |
 | 
						|
                ControlStyles.ResizeRedraw |
 | 
						|
                DisplayHelp.DoubleBufferFlag |
 | 
						|
                ControlStyles.SupportsTransparentBackColor, true);
 | 
						|
 | 
						|
            BackColor = Color.Transparent;
 | 
						|
            Colors.RadialMenuButtonBackground = Color.Transparent;
 | 
						|
 | 
						|
            ItemClick += GridRadialMenuEditControl_ItemClick;
 | 
						|
        }
 | 
						|
 | 
						|
        #region GridRadialMenuEditControl_ItemClick
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// RadialMenu item click handler
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        private void GridRadialMenuEditControl_ItemClick(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (_SuspendUpdate == false)
 | 
						|
            {
 | 
						|
                RadialMenuItem item = sender as RadialMenuItem;
 | 
						|
 | 
						|
                if (item != null)
 | 
						|
                    OnGridRadialMenuEditControl_ItemClick(item);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #region OnGridRadialMenuEditControl_ItemClick
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// RadialMenu item click handler
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="item"></param>
 | 
						|
        public virtual void OnGridRadialMenuEditControl_ItemClick(RadialMenuItem item)
 | 
						|
        {
 | 
						|
            if ((item.Text != null && item.Text.Equals(_Cell.Value) == false) ||
 | 
						|
            (item.Text == null && _Cell.Value != null))
 | 
						|
            {
 | 
						|
                _Cell.Value = item.Text;
 | 
						|
 | 
						|
                _Cell.EditorValueChanged(this);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region OnInvalidated
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// OnInvalidated
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected override void OnInvalidated(InvalidateEventArgs e)
 | 
						|
        {
 | 
						|
            base.OnInvalidated(e);
 | 
						|
 | 
						|
            if (_Cell != null && _SuspendUpdate == false)
 | 
						|
                _Cell.InvalidateRender();
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region GetValue
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// GetValue
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="value"></param>
 | 
						|
        ///<returns></returns>
 | 
						|
        public virtual string GetValue(object value)
 | 
						|
        {
 | 
						|
            GridPanel panel = _Cell.GridPanel;
 | 
						|
 | 
						|
            if (value == null ||
 | 
						|
                (panel.NullValue == NullValue.DBNull && value == DBNull.Value))
 | 
						|
            {
 | 
						|
                return (_Cell.NullString);
 | 
						|
            }
 | 
						|
 | 
						|
            if (_Cell.IsValueExpression == true)
 | 
						|
                value = _Cell.GetExpValue((string)value);
 | 
						|
 | 
						|
            return (value.ToString());
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region FindItemByText
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Finds the RadialMenuItem based upon the given item Text.
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="items"></param>
 | 
						|
        /// <param name="text"></param>
 | 
						|
        /// <returns>RadialMenuItem or null</returns>
 | 
						|
        public RadialMenuItem FindItemByText(SubItemsCollection items, string text)
 | 
						|
        {
 | 
						|
            if (string.IsNullOrEmpty(text))
 | 
						|
                return (null);
 | 
						|
 | 
						|
            foreach (RadialMenuItem item in items)
 | 
						|
            {
 | 
						|
                if (item.Text.Equals(text))
 | 
						|
                    return (item);
 | 
						|
 | 
						|
                if (item.SubItems.Count > 0)
 | 
						|
                {
 | 
						|
                    RadialMenuItem item2 = FindItemByText(item.SubItems, text);
 | 
						|
 | 
						|
                    if (item2 != null)
 | 
						|
                        return (item2);
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
            return (null);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region IGridCellEditControl Members
 | 
						|
 | 
						|
        #region Public properties
 | 
						|
 | 
						|
        #region CanInterrupt
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// CanInterrupt
 | 
						|
        /// </summary>
 | 
						|
        public bool CanInterrupt
 | 
						|
        {
 | 
						|
            get { return (true); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region CellEditMode
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// CellEditMode
 | 
						|
        /// </summary>
 | 
						|
        public CellEditMode CellEditMode
 | 
						|
        {
 | 
						|
            get { return (CellEditMode.NonModal); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorCell
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// EditorCell
 | 
						|
        /// </summary>
 | 
						|
        public GridCell EditorCell
 | 
						|
        {
 | 
						|
            get { return (_Cell); }
 | 
						|
            set { _Cell = value; }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorCellBitmap
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// EditorCellBitmap
 | 
						|
        ///</summary>
 | 
						|
        public Bitmap EditorCellBitmap
 | 
						|
        {
 | 
						|
            get { return (_EditorCellBitmap); }
 | 
						|
 | 
						|
            set
 | 
						|
            {
 | 
						|
                if (_EditorCellBitmap != null)
 | 
						|
                    _EditorCellBitmap.Dispose();
 | 
						|
 | 
						|
                _EditorCellBitmap = value;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorFormattedValue
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// EditorFormattedValue
 | 
						|
        ///</summary>
 | 
						|
        public virtual string EditorFormattedValue
 | 
						|
        {
 | 
						|
            get { return (Text); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorPanel
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// EditorPanel
 | 
						|
        /// </summary>
 | 
						|
        public EditorPanel EditorPanel
 | 
						|
        {
 | 
						|
            get { return (_EditorPanel); }
 | 
						|
            set { _EditorPanel = value; }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorValue
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// EditorValue
 | 
						|
        /// </summary>
 | 
						|
        public virtual object EditorValue
 | 
						|
        {
 | 
						|
            get { return (Text); }
 | 
						|
            set { Text = GetValue(value); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorValueChanged
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// EditorValueChanged
 | 
						|
        /// </summary>
 | 
						|
        public virtual bool EditorValueChanged
 | 
						|
        {
 | 
						|
            get { return (_ValueChanged); }
 | 
						|
 | 
						|
            set
 | 
						|
            {
 | 
						|
                if (_ValueChanged != value)
 | 
						|
                {
 | 
						|
                    _ValueChanged = value;
 | 
						|
 | 
						|
                    if (value == true)
 | 
						|
                        _Cell.SetEditorDirty(this);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EditorValueType
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// EditorValueType
 | 
						|
        ///</summary>
 | 
						|
        public virtual Type EditorValueType
 | 
						|
        {
 | 
						|
            get { return (typeof(string)); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region StretchBehavior
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// StretchBehavior
 | 
						|
        /// </summary>
 | 
						|
        public virtual StretchBehavior StretchBehavior
 | 
						|
        {
 | 
						|
            get { return (_StretchBehavior); }
 | 
						|
            set { _StretchBehavior = value; }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region SuspendUpdate
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// SuspendUpdate
 | 
						|
        /// </summary>
 | 
						|
        public virtual bool SuspendUpdate
 | 
						|
        {
 | 
						|
            get { return (_SuspendUpdate); }
 | 
						|
            set { _SuspendUpdate = value; }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region ValueChangeBehavior
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// ValueChangeBehavior
 | 
						|
        /// </summary>
 | 
						|
        public virtual ValueChangeBehavior ValueChangeBehavior
 | 
						|
        {
 | 
						|
            get { return (ValueChangeBehavior.InvalidateRender); }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region InitializeContext
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// InitializeContext
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="cell"></param>
 | 
						|
        ///<param name="style"></param>
 | 
						|
        public virtual void InitializeContext(GridCell cell, CellVisualStyle style)
 | 
						|
        {
 | 
						|
            _Cell = cell;
 | 
						|
 | 
						|
            if (style != null)
 | 
						|
            {
 | 
						|
                Enabled = (_Cell.IsReadOnly == false);
 | 
						|
 | 
						|
                Font = style.Font;
 | 
						|
                ForeColor = style.TextColor;
 | 
						|
            }
 | 
						|
 | 
						|
            Text = GetValue(_Cell.Value);
 | 
						|
 | 
						|
            _ValueChanged = false;
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region GetProposedSize
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// GetProposedSize
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="g"></param>
 | 
						|
        ///<param name="cell"></param>
 | 
						|
        ///<param name="style"></param>
 | 
						|
        ///<param name="constraintSize"></param>
 | 
						|
        ///<returns></returns>
 | 
						|
        public virtual Size GetProposedSize(Graphics g,
 | 
						|
            GridCell cell, CellVisualStyle style, Size constraintSize)
 | 
						|
        {
 | 
						|
            Size size = GetPreferredSize(Size.Empty);
 | 
						|
 | 
						|
            int n = Dpi.Width(CenterButtonDiameter);
 | 
						|
 | 
						|
            if (n > size.Width)
 | 
						|
                size.Width = n;
 | 
						|
 | 
						|
            n = Dpi.Height(CenterButtonDiameter);
 | 
						|
 | 
						|
            if (n > size.Height)
 | 
						|
                size.Height = n;
 | 
						|
 | 
						|
            return (size);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Edit support
 | 
						|
 | 
						|
        #region BeginEdit
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// BeginEdit
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="selectAll"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public virtual bool BeginEdit(bool selectAll)
 | 
						|
        {
 | 
						|
            return (false);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region EndEdit
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// EndEdit
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        public virtual bool EndEdit()
 | 
						|
        {
 | 
						|
            return (false);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region CancelEdit
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// CancelEdit
 | 
						|
        /// </summary>
 | 
						|
        /// <returns></returns>
 | 
						|
        public virtual bool CancelEdit()
 | 
						|
        {
 | 
						|
            return (false);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region CellRender
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// CellRender
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="g"></param>
 | 
						|
        public virtual void CellRender(Graphics g)
 | 
						|
        {
 | 
						|
            _Cell.CellRender(this, g);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Keyboard support
 | 
						|
 | 
						|
        #region CellKeyDown
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// CellKeyDown
 | 
						|
        ///</summary>
 | 
						|
        public virtual void CellKeyDown(KeyEventArgs e)
 | 
						|
        {
 | 
						|
            OnKeyDown(e);
 | 
						|
            OnKeyUp(e);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region WantsInputKey
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// WantsInputKey
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="key"></param>
 | 
						|
        /// <param name="gridWantsKey"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        public virtual bool WantsInputKey(Keys key, bool gridWantsKey)
 | 
						|
        {
 | 
						|
            switch (key & Keys.KeyCode)
 | 
						|
            {
 | 
						|
                case Keys.Space:
 | 
						|
                    return (true);
 | 
						|
 | 
						|
                default:
 | 
						|
                    return (gridWantsKey == false);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region Mouse support
 | 
						|
 | 
						|
        #region OnCellMouseMove
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// OnCellMouseMove
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="e"></param>
 | 
						|
        public virtual void OnCellMouseMove(MouseEventArgs e)
 | 
						|
        {
 | 
						|
            OnMouseMove(e);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region OnCellMouseEnter
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// OnCellMouseEnter
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="e"></param>
 | 
						|
        public virtual void OnCellMouseEnter(EventArgs e)
 | 
						|
        {
 | 
						|
            Point pt = _Cell.SuperGrid.PointToClient(MousePosition);
 | 
						|
 | 
						|
            OnMouseEnter(e);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region OnCellMouseLeave
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// OnCellMouseLeave
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="e"></param>
 | 
						|
        public virtual void OnCellMouseLeave(EventArgs e)
 | 
						|
        {
 | 
						|
            if (_Cell != null)
 | 
						|
            {
 | 
						|
                Refresh();
 | 
						|
                OnMouseLeave(e);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region OnCellMouseUp
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// OnCellMouseUp
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="e"></param>
 | 
						|
        public virtual void OnCellMouseUp(MouseEventArgs e)
 | 
						|
        {
 | 
						|
            OnMouseUp(e);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region OnCellMouseDown
 | 
						|
 | 
						|
        ///<summary>
 | 
						|
        /// OnCellMouseDown
 | 
						|
        ///</summary>
 | 
						|
        ///<param name="e"></param>
 | 
						|
        public virtual void OnCellMouseDown(MouseEventArgs e)
 | 
						|
        {
 | 
						|
            OnMouseDown(e);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #endregion  
 | 
						|
 | 
						|
        #region Dispose
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Dispose
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="disposing"></param>
 | 
						|
        protected override void Dispose(bool disposing)
 | 
						|
        {
 | 
						|
            base.Dispose(disposing);
 | 
						|
        }
 | 
						|
 | 
						|
        #endregion
 | 
						|
    }
 | 
						|
}
 |