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

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

namespace EhLib
{

  [DataAxisGridPropBarDesignTimeVisibleAttribute(true)]
  public class DataVertGridRadioButtonRow : DataVertGridMonoCellRow, IRadioButtonDataCellHolder
  {

    #region private consts
    //private static readonly object EventKey_GetCheckboxState = new object();
    #endregion private consts

    #region privates
    #endregion privates

    public DataVertGridRadioButtonRow()
    {

    }

    #region properties
    [DefaultValue(null)]
    [TypeConverter(typeof(StringConverter))]
    public object TrueValue
    {
      get { return DataCell.TrueValue; }
      set { DataCell.TrueValue = value; }
    }

    [DefaultValue(null)]
    [TypeConverter(typeof(StringConverter))]
    public object FalseValue
    {
      get { return DataCell.FalseValue; }
      set { DataCell.FalseValue = value; }
    }

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

    #region run-rime properties
    [Browsable(false)]
    public new DataAxisGridRadioButtonDataCell DataCell
    {
      get { return (DataAxisGridRadioButtonDataCell)base.DataCell; }
    }
    #endregion

    #region events
    #endregion events

    #region Methods
    protected override DataAxisGridDataCellMan CreateTemplateCell()
    {
      return new DataAxisGridRadioButtonDataCell();
    }

    public void SetCheckedStateAsChecked(PropertyAxisBar propAxisBar, object listItemBar)
    {
      bool listItemState;
      bool curState = GetCheckedState(propAxisBar, listItemBar);

      if (curState == false)
      {
        foreach (object li in Grid.DataLink.CurrencyManager.List)
        {
          listItemState = GetCheckedState(this, li);
          if ((li != listItemBar) && (listItemState == true) && (PropDescr != null))
            PropDescr.SetValue(li, false);
        }
      }
      Debug.Assert(PropDescr != null, @"PropDescr != null");
      PropDescr.SetValue(((DataGridRow)listItemBar).SourceItem, true);
    }

    public virtual bool GetCheckedState(PropertyAxisBar propAxisBar, object listItemBar)
    {
      object value = propAxisBar.GetValue(listItemBar);
      bool result = GetCheckedStateFromValue(value);
      return result;
    }

    public bool GetCheckedStateFromValue(object value)
    {
      if ((value != null) && (value.Equals(true)))
        return true;
      else
        return false;
    }
    #endregion

  }

}
