//------------------------------------------------------------------------------
// <copyright file=”*.cs” company=”EhLib Team”>
//     Copyright (c) 2017 Dmitry V. Bolshakov   
// </copyright>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace EhLib
{

  [DataAxisGridPropBarDesignTimeVisibleAttribute(true)]
  public class DataGridButtonColumn : DataGridMonoCellColumn
  {
    #region privates
    #endregion

    public DataGridButtonColumn()
    {
    }

    #region properties
    [Browsable(false)]
    public new DataAxisGridButtonDataCell DataCell
    {
      get { return (DataAxisGridButtonDataCell)base.DataCell; }
    }

    [DefaultValue(FlatStyle.Standard) ]
    public FlatStyle FlatStyle
    {
      get { return DataCell.FlatStyle; }
      set { DataCell.FlatStyle = value; }
    }

    public string Text
    {
      get { return DataCell.Text; }
      set { DataCell.Text = value; }
    }

    [ DefaultValue(false) ]
    public bool UseColumnTextForButtonValue
    {
      get { return DataCell.UseColumnTextForButtonValue; }
      set { DataCell.UseColumnTextForButtonValue = value; }
    }
    #endregion

    #region methods
    protected override DataAxisGridDataCellMan CreateTemplateCell()
    {
      return new DataAxisGridButtonDataCell();
    }

    protected internal override void PaintCellBackground(
      DataAxisGridDataCellMan cellMan, DataAxisGridDataCellPaintEventArgs e)
    {
      Color baseColor;
      int alpha;

      if ((Grid.Focused) &&
          (Grid.Selection.SelectionType == GridSelectionType.None) &&
          ((BasePaintCellStates.Current & e.State) != 0))
      {
        using (
          SolidBrush fillBrush = new SolidBrush(Grid.BackColor))
        {
          e.Graphics.FillRectangle(fillBrush, e.CellRect);
        }

        if (Grid.Selection.RowHighlight)
        {
          baseColor = SystemColors.Highlight;
          alpha = 255 / 4;
          using (
            SolidBrush fillBrush = new SolidBrush(Color.FromArgb(alpha, baseColor)))
          {
            e.Graphics.FillRectangle(fillBrush, e.CellRect);
          }
        }
      }
      else
      {
        base.PaintCellBackground(cellMan, e);
      }
    }
    #endregion
  }
}
