using System; using System.Diagnostics; using CPF.Drawing; using CPF.ReoGrid.Events; using CPF.ReoGrid.Graphics; using CPF.ReoGrid.Interaction; using CPF.ReoGrid.Rendering; using CPF.ReoGrid.Utility; namespace CPF.ReoGrid.CellTypes { [Serializable] public class ButtonCell : CellBody { public ButtonCell() { } public ButtonCell(string defaultText) { this.defaultText = defaultText; } public override void OnSetup(Cell cell) { bool flag = cell != null; if (flag) { bool flag2 = cell.Worksheet != null; if (flag2) { cell.Worksheet.SetRangeStyles(cell.PositionAsRange, new WorksheetRangeStyle { Flag = PlainStyleFlag.AlignAll, HAlign = ReoGridHorAlign.Center, VAlign = ReoGridVerAlign.Middle }); } bool flag3 = !string.IsNullOrEmpty(this.defaultText); if (flag3) { cell.Data = this.defaultText; } } } public override void OnPaint(CellDrawingContext dc) { bool flag = base.Cell != null; if (flag) { this.DrawButton(dc); } dc.DrawCellText(); } protected virtual void DrawButton(CellDrawingContext dc) { IGraphics graphics = dc.Graphics; Rect bounds = this.Bounds; graphics.DrawRectangle(bounds, ColorUtility.ChangeColorBrightness(StaticResources.SystemColor_ControlDark, -0.3f)); float num = bounds.X + 1f; float num2 = bounds.Y + 1f; float num3 = bounds.Width - 2f; float num4 = bounds.Height - 2f; Rect rect = new Rect(ref num, ref num2, ref num3, ref num4); graphics.FillRectangle(rect, StaticResources.SystemColor_Control); bool isPressed = this.IsPressed; if (isPressed) { num = bounds.X + 1f; num2 = bounds.Y + 1f; num3 = bounds.Width - 2f; num4 = bounds.Height - 2f; Rect rect2 = new Rect(ref num, ref num2, ref num3, ref num4); graphics.DrawRectangle(rect2, ColorUtility.ChangeColorBrightness(StaticResources.SystemColor_ControlDark, -0.3f)); } } public override bool OnMouseDown(CellMouseEventArgs e) { Rect bounds = this.Bounds; Point relativePosition = e.RelativePosition; bool flag = bounds.Contains(relativePosition); bool result; if (flag) { this.IsPressed = true; result = true; } else { result = false; } return result; } public override bool OnMouseUp(CellMouseEventArgs e) { bool isPressed = this.IsPressed; bool result; if (isPressed) { Rect bounds = this.Bounds; Point relativePosition = e.RelativePosition; bool flag = bounds.Contains(relativePosition); if (flag) { this.PerformClick(); } this.IsPressed = false; result = true; } else { result = false; } return result; } public override bool OnKeyDown(KeyCode keyCode) { bool flag = keyCode == KeyCode.Space; bool result; if (flag) { this.IsPressed = true; result = true; } else { result = false; } return result; } public override bool OnKeyUp(KeyCode keyCode) { bool flag = keyCode == KeyCode.Space && this.IsPressed; bool result; if (flag) { this.IsPressed = false; this.PerformClick(); result = true; } else { result = false; } return result; } public override bool OnStartEdit() { return false; } public bool IsPressed { get; set; } public virtual void PerformClick() { EventHandler click = this.Click; if (click != null) { click(this, null); } } //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event EventHandler Click; public override ICellBody Clone() { return new ButtonCell(base.Cell.DisplayText); } private string defaultText; } }