using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar.SuperGrid.Style;
using DevComponents.Instrumentation;
namespace DevComponents.DotNetBar.SuperGrid
{
///
/// GridGaugeEditControl
///
[ToolboxItem(false)]
public class GridGaugeEditControl : GaugeControl, IGridCellEditControl
{
#region Private variables
private GridCell _Cell;
private EditorPanel _EditorPanel;
private Bitmap _EditorCellBitmap;
private bool _ValueChanged;
private bool _SuspendUpdate;
private string _PointerName = "Pointer1";
private StretchBehavior _StretchBehavior = StretchBehavior.Both;
#endregion
///
/// GridGaugeEditControl
///
public GridGaugeEditControl()
{
PointerValueChanged += OnValueChanged;
#if !TRIAL
LicenseKey = "F962CEC7-CD8F-4911-A9E9-CAB39962FC1F";
#endif
}
#region Public properties
///
/// PointerName
///
public string PointerName
{
get { return (_PointerName); }
set { _PointerName = value; }
}
#endregion
#region OnValueChanged
///
/// Pointer Value changed
///
///
///
protected virtual void OnValueChanged(object sender, PointerChangedEventArgs e)
{
if (_Cell != null && _SuspendUpdate == false)
{
_Cell.Value = e.NewValue;
_Cell.EditorValueChanged(this);
}
}
#endregion
#region OnInvalidated
///
/// OnInvalidated
///
///
protected override void OnInvalidated(InvalidateEventArgs e)
{
base.OnInvalidated(e);
if (_Cell != null && _SuspendUpdate == false)
_Cell.InvalidateRender();
}
#endregion
#region OnPaintBackground
///
/// OnPaintBackground
///
///
protected override void OnPaintBackground(PaintEventArgs e)
{
_Cell.PaintEditorBackground(e, this);
}
#endregion
#region GetValue
///
/// GetValue
///
///
///
public virtual double GetValue(object value)
{
GridPanel panel = _Cell.GridPanel;
if (value == null ||
(panel.NullValue == NullValue.DBNull && value == DBNull.Value))
{
return (0);
}
if (_Cell.IsValueExpression == true)
value = _Cell.GetExpValue((string)value);
return (Convert.ToDouble(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.InPlace); }
}
#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 { 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 (GetPointerValue(_PointerName)); }
set { SetPointerValue(_PointerName, GetValue(value), false); }
}
#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(string)); }
}
#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;
}
SetPointerValue(_PointerName, GetValue(_Cell.Value), false);
_ValueChanged = false;
}
#endregion
#region GetProposedSize
///
/// GetProposedSize
///
///
///
///
///
///
public virtual Size GetProposedSize(Graphics g,
GridCell cell, CellVisualStyle style, Size constraintSize)
{
Size size = constraintSize;
size.Height = size.Width;
if (size.Width == 0)
size.Width = cell.Size.Width - Dpi.Width2;
size.Height = Dpi.Height50;
return (size);
}
#endregion
#region Edit support
#region BeginEdit
///
/// BeginEdit
///
///
///
public virtual bool BeginEdit(bool selectAll)
{
return (false);
}
#endregion
#region EndEdit
///
/// EndEdit
///
///
public virtual bool EndEdit()
{
return (false);
}
#endregion
#region CancelEdit
///
/// CancelEdit
///
///
public virtual bool CancelEdit()
{
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)
{
switch (e.KeyData)
{
case Keys.T:
break;
case Keys.F:
break;
default:
OnKeyDown(e);
break;
}
}
#endregion
#region WantsInputKey
///
/// WantsInputKey
///
///
///
///
public virtual bool WantsInputKey(Keys key, bool gridWantsKey)
{
switch (key & Keys.KeyCode)
{
case Keys.T:
case Keys.F:
case Keys.Space:
return (true);
default:
return (gridWantsKey == false);
}
}
#endregion
#endregion
#region Mouse support
#region OnCellMouseMove
///
/// OnCellMouseMove
///
///
public virtual void OnCellMouseMove(MouseEventArgs e)
{
OnMouseMove(e);
_Cell.SuperGrid.GridCursor = Cursor;
}
#endregion
#region OnCellMouseEnter
///
/// OnCellMouseEnter
///
///
public virtual void OnCellMouseEnter(EventArgs e)
{
OnMouseEnter(e);
}
#endregion
#region OnCellMouseLeave
///
/// OnCellMouseLeave
///
///
public virtual void OnCellMouseLeave(EventArgs e)
{
OnMouseLeave(e);
}
#endregion
#region OnCellMouseUp
///
/// OnCellMouseUp
///
///
public virtual void OnCellMouseUp(MouseEventArgs e)
{
OnMouseUp(e);
}
#endregion
#region OnCellMouseDown
///
/// OnCellMouseDown
///
///
public virtual void OnCellMouseDown(MouseEventArgs e)
{
OnMouseDown(e);
}
#endregion
#endregion
#endregion
#region Dispose
///
/// Dispose
///
///
protected override void Dispose(bool disposing)
{
PointerValueChanged -= OnValueChanged;
base.Dispose(disposing);
}
#endregion
}
}