using System; using System.ComponentModel; using System.Data.SqlTypes; using System.Drawing; using System.Windows.Forms; using DevComponents.DotNetBar.SuperGrid.Style; using DevComponents.Editors; namespace DevComponents.DotNetBar.SuperGrid { /// /// GridIntegerInputEditControl /// [ToolboxItem(false)] public class GridIntegerInputEditControl : IntegerInput, 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 /// /// GridIntegerInputEditControl /// public GridIntegerInputEditControl() { ShowUpDown = true; } #region OnValueChanged /// /// OnValueChanged /// /// protected override void OnValueChanged(EventArgs e) { if (_Cell != null && _SuspendUpdate == false) _Cell.EditorValueChanged(this); base.OnValueChanged(e); } #endregion #region GetValue /// /// GetValue /// /// /// public virtual int GetValue(object value) { GridPanel panel = _Cell.GridPanel; if (value == null || (panel.NullValue == NullValue.DBNull && value == DBNull.Value)) { return (0); } if (value is SqlInt16) { SqlInt16 sdt = (SqlInt16) value; if (sdt.IsNull == true) return (0); return (sdt.Value); } if (value is SqlInt32) { SqlInt32 sdt = (SqlInt32)value; if (sdt.IsNull == true) return (0); return (sdt.Value); } if (_Cell.IsValueExpression == true) value = _Cell.GetExpValue((string)value); return (Convert.ToInt32(value)); } #endregion #region IGridCellEditControl Members #region Public properties #region CanInterrupt /// /// CanInterrupt /// public bool CanInterrupt { get { return (true); } } #endregion #region CellEditMode /// /// CellEditMode /// public CellEditMode CellEditMode { get { return (CellEditMode.Modal); } } #endregion #region EditorCell /// /// EditorCell /// public GridCell EditorCell { get { return (_Cell); } set { _Cell = value; } } #endregion #region EditorCellBitmap /// /// EditorCellBitmap /// public Bitmap EditorCellBitmap { get { return (_EditorCellBitmap); } set { if (_EditorCellBitmap != null) _EditorCellBitmap.Dispose(); _EditorCellBitmap = value; } } #endregion #region EditorFormattedValue /// /// EditorFormattedValue /// public virtual string EditorFormattedValue { get { if (_Cell != null && _Cell.IsValueNull == true) return (_Cell.NullString); return (Text); } } #endregion #region EditorPanel /// /// EditorPanel /// public EditorPanel EditorPanel { get { return (_EditorPanel); } set { _EditorPanel = value; } } #endregion #region EditorValue /// /// EditorValue /// public virtual object EditorValue { get { return (Value); } set { Value = GetValue(value); } } #endregion #region EditorValueChanged /// /// EditorValueChanged /// public virtual bool EditorValueChanged { get { return (_ValueChanged); } set { if (_ValueChanged != value) { _ValueChanged = value; if (value == true) _Cell.SetEditorDirty(this); } } } #endregion #region EditorValueType /// /// EditorValueType /// public virtual Type EditorValueType { get { return (typeof(int)); } } #endregion #region StretchBehavior /// /// StretchBehavior /// public virtual StretchBehavior StretchBehavior { get { return (_StretchBehavior); } set { _StretchBehavior = value; } } #endregion #region SuspendUpdate /// /// SuspendUpdate /// public bool SuspendUpdate { get { return (_SuspendUpdate); } set { _SuspendUpdate = value; } } #endregion #region ValueChangeBehavior /// /// ValueChangeBehavior /// public virtual ValueChangeBehavior ValueChangeBehavior { get { return (ValueChangeBehavior.InvalidateRender); } } #endregion #endregion #region InitializeContext /// /// InitializeContext /// /// /// public virtual void InitializeContext(GridCell cell, CellVisualStyle style) { _Cell = cell; if (style != null) { Enabled = (_Cell.ReadOnly == false); Font = style.Font; ForeColor = style.TextColor; } Value = GetValue(cell.Value); _ValueChanged = false; } #endregion #region GetProposedSize /// /// GetProposedSize /// /// /// /// /// /// public virtual Size GetProposedSize(Graphics g, GridCell cell, CellVisualStyle style, Size constraintSize) { Size size = GetPreferredSize(constraintSize); return (size); } #endregion #region Edit support #region BeginEdit /// /// BeginEdit /// /// /// public virtual bool BeginEdit(bool selectAll) { if (FreeTextEntryMode == true) { TextBox box = GetFreeTextBox() as TextBox; if (box != null) { if (selectAll == true) box.SelectAll(); } } return (false); } #endregion #region EndEdit /// /// EndEdit /// /// public virtual bool EndEdit() { CloseDropDown(); return (false); } #endregion #region CancelEdit /// /// CancelEdit /// /// public virtual bool CancelEdit() { CloseDropDown(); return (false); } #endregion #endregion #region CellRender /// /// CellRender /// /// public virtual void CellRender(Graphics g) { _Cell.CellRender(this, g); } #endregion #region Keyboard support #region CellKeyDown /// /// CellKeyDown /// public virtual void CellKeyDown(KeyEventArgs e) { } #endregion #region WantsInputKey /// /// WantsInputKey /// /// /// /// public virtual bool WantsInputKey(Keys key, bool gridWantsKey) { if ((key & Keys.KeyCode) == Keys.Tab) { ApplyFreeTextValue(); return (false); } if (IsCalculatorDisplayed == true) return (true); switch (key & Keys.KeyCode) { case Keys.Left: case Keys.Right: case Keys.Home: case Keys.End: case Keys.Up: case Keys.Down: return (true); case Keys.Enter: ApplyFreeTextValue(); return (gridWantsKey == false); default: return (gridWantsKey == false); } } #endregion #endregion #region Mouse support #region OnCellMouseMove /// /// OnCellMouseMove /// /// public virtual void OnCellMouseMove(MouseEventArgs e) { } #endregion #region OnCellMouseEnter /// /// OnCellMouseEnter /// /// public virtual void OnCellMouseEnter(EventArgs e) { } #endregion #region OnCellMouseLeave /// /// OnCellMouseLeave /// /// public virtual void OnCellMouseLeave(EventArgs e) { } #endregion #region OnCellMouseUp /// /// OnCellMouseUp /// /// public virtual void OnCellMouseUp(MouseEventArgs e) { } #endregion #region OnCellMouseDown /// /// OnCellMouseDown /// /// public virtual void OnCellMouseDown(MouseEventArgs e) { } #endregion #endregion #endregion #region IGridCellEditorFocus members #region FocusEditor /// /// Gives focus to the editor /// public void FocusEditor() { if (IsEditorFocused == false) { if (FreeTextEntryMode == true) { TextBox box = GetFreeTextBox() as TextBox; if (box != null) box.Focus(); } else { Focus(); } } } #endregion #region IsEditorFocused /// /// Gets whether editor has the focus /// public bool IsEditorFocused { get { if (FreeTextEntryMode == true) { TextBox box = GetFreeTextBox() as TextBox; if (box != null) return (box.Focused); } return (Focused); } } #endregion #endregion } }