/// <summary>
        /// Raises the KeyDown event
        /// </summary>
        /// <param name="e">A CellKeyEventArgs that contains the event data</param>
        public override void OnKeyDown(CellKeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyData == Keys.Space && e.Table.IsCellEditable(e.CellPos))
            {
                // get the renderer data
                CheckBoxRendererData rendererData = this.GetCheckBoxRendererData(e.Cell);

                //
                if (e.Cell.CheckState == CheckState.Checked)
                {
                    rendererData.CheckState = CheckBoxStates.CheckedPressed;
                }
                else if (e.Cell.CheckState == CheckState.Indeterminate)
                {
                    rendererData.CheckState = CheckBoxStates.MixedPressed;
                }
                else                 //if (e.Cell.CheckState == CheckState.Unchecked)
                {
                    rendererData.CheckState = CheckBoxStates.UncheckedPressed;
                }

                e.Table.Invalidate(e.CellRect);
            }
        }
        /// <summary>
        /// Raises the MouseDown event
        /// </summary>
        /// <param name="e">A CellMouseEventArgs that contains the event data</param>
        public override void OnMouseDown(CellMouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Table.IsCellEditable(e.CellPos))
            {
                // get the renderer data
                CheckBoxRendererData rendererData = this.GetCheckBoxRendererData(e.Cell);

                if (this.CalcCheckRect(e.Table.TableModel.Rows[e.Row].Alignment, e.Table.ColumnModel.Columns[e.Column].Alignment).Contains(e.X, e.Y))
                {
                    //
                    if (e.Cell.CheckState == CheckState.Checked)
                    {
                        rendererData.CheckState = CheckBoxStates.CheckedPressed;
                    }
                    else if (e.Cell.CheckState == CheckState.Indeterminate)
                    {
                        rendererData.CheckState = CheckBoxStates.MixedPressed;
                    }
                    else                     //if (e.Cell.CheckState == CheckState.Unchecked)
                    {
                        rendererData.CheckState = CheckBoxStates.UncheckedPressed;
                    }

                    e.Table.Invalidate(e.CellRect);
                }
            }
        }
        /// <summary>
        /// Gets the CheckBoxCellRenderer specific data used by the Renderer from
        /// the specified Cell
        /// </summary>
        /// <param name="cell">The Cell to get the CheckBoxCellRenderer data for</param>
        /// <returns>The CheckBoxCellRenderer data for the specified Cell</returns>
        protected CheckBoxRendererData GetCheckBoxRendererData(Cell cell)
        {
            object rendererData = this.GetRendererData(cell);

            if (rendererData == null || !(rendererData is CheckBoxRendererData))
            {
                if (cell.CheckState == CheckState.Unchecked)
                {
                    rendererData = new CheckBoxRendererData(CheckBoxStates.UncheckedNormal);
                }
                else if (cell.CheckState == CheckState.Indeterminate && cell.ThreeState)
                {
                    rendererData = new CheckBoxRendererData(CheckBoxStates.MixedNormal);
                }
                else
                {
                    rendererData = new CheckBoxRendererData(CheckBoxStates.CheckedNormal);
                }

                this.SetRendererData(cell, rendererData);
            }

            this.ValidateCheckState(cell, (CheckBoxRendererData)rendererData);

            return((CheckBoxRendererData)rendererData);
        }
        /// <summary>
        /// Corrects any differences between the check state of the specified Cell
        /// and the check state in its rendererData
        /// </summary>
        /// <param name="cell">The Cell to chech</param>
        /// <param name="rendererData">The CheckBoxRendererData to check</param>
        private void ValidateCheckState(Cell cell, CheckBoxRendererData rendererData)
        {
            switch (cell.CheckState)
            {
            case CheckState.Checked:
            {
                if (rendererData.CheckState <= CheckBoxStates.UncheckedDisabled)
                {
                    rendererData.CheckState |= (CheckBoxStates)4;
                }
                else if (rendererData.CheckState >= CheckBoxStates.MixedNormal)
                {
                    rendererData.CheckState -= (CheckBoxStates)4;
                }

                break;
            }

            case CheckState.Indeterminate:
            {
                if (rendererData.CheckState <= CheckBoxStates.UncheckedDisabled)
                {
                    rendererData.CheckState |= (CheckBoxStates)8;
                }
                else if (rendererData.CheckState <= CheckBoxStates.CheckedDisabled)
                {
                    rendererData.CheckState |= (CheckBoxStates)4;
                }

                break;
            }

            default:
            {
                if (rendererData.CheckState >= CheckBoxStates.MixedNormal)
                {
                    rendererData.CheckState -= (CheckBoxStates)8;
                }
                else if (rendererData.CheckState >= CheckBoxStates.CheckedNormal)
                {
                    rendererData.CheckState -= (CheckBoxStates)4;
                }

                break;
            }
            }
        }
        /// <summary>
        /// Raises the MouseUp event
        /// </summary>
        /// <param name="e">A CellMouseEventArgs that contains the event data</param>
        public override void OnMouseUp(CellMouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (e.Table.IsCellEditable(e.CellPos))
            {
                // get the renderer data
                CheckBoxRendererData rendererData = this.GetCheckBoxRendererData(e.Cell);

                if (this.CalcCheckRect(e.Table.TableModel.Rows[e.Row].Alignment, e.Table.ColumnModel.Columns[e.Column].Alignment).Contains(e.X, e.Y))
                {
                    if (e.Button == MouseButtons.Left && e.Table.LastMouseDownCell.Row == e.Row && e.Table.LastMouseDownCell.Column == e.Column)
                    {
                        //
                        if (e.Cell.CheckState == CheckState.Checked)
                        {
                            if (!e.Cell.ThreeState || !(e.Table.ColumnModel.Columns[e.Column] is CheckBoxColumn) ||
                                ((CheckBoxColumn)e.Table.ColumnModel.Columns[e.Column]).CheckStyle == CheckBoxColumnStyle.RadioButton)
                            {
                                rendererData.CheckState = CheckBoxStates.UncheckedHot;
                                e.Cell.CheckState       = CheckState.Unchecked;
                            }
                            else
                            {
                                rendererData.CheckState = CheckBoxStates.MixedHot;
                                e.Cell.CheckState       = CheckState.Indeterminate;
                            }
                        }
                        else if (e.Cell.CheckState == CheckState.Indeterminate)
                        {
                            rendererData.CheckState = CheckBoxStates.UncheckedHot;
                            e.Cell.CheckState       = CheckState.Unchecked;
                        }
                        else                         //if (e.Cell.CheckState == CheckState.Unchecked)
                        {
                            rendererData.CheckState = CheckBoxStates.CheckedHot;
                            e.Cell.CheckState       = CheckState.Checked;
                        }

                        e.Table.Invalidate(e.CellRect);
                    }
                }
            }
        }
        /// <summary>
        /// Raises the MouseLeave event
        /// </summary>
        /// <param name="e">A CellMouseEventArgs that contains the event data</param>
        public override void OnMouseLeave(CellMouseEventArgs e)
        {
            base.OnMouseLeave(e);

            if (e.Table.IsCellEditable(e.CellPos))
            {
                // get the renderer data
                CheckBoxRendererData rendererData = this.GetCheckBoxRendererData(e.Cell);

                if (e.Cell.CheckState == CheckState.Checked)
                {
                    if (rendererData.CheckState != CheckBoxStates.CheckedNormal)
                    {
                        rendererData.CheckState = CheckBoxStates.CheckedNormal;

                        e.Table.Invalidate(e.CellRect);
                    }
                }
                else if (e.Cell.CheckState == CheckState.Indeterminate)
                {
                    if (rendererData.CheckState != CheckBoxStates.MixedNormal)
                    {
                        rendererData.CheckState = CheckBoxStates.MixedNormal;

                        e.Table.Invalidate(e.CellRect);
                    }
                }
                else                 //if (e.Cell.CheckState == CheckState.Unchecked)
                {
                    if (rendererData.CheckState != CheckBoxStates.UncheckedNormal)
                    {
                        rendererData.CheckState = CheckBoxStates.UncheckedNormal;

                        e.Table.Invalidate(e.CellRect);
                    }
                }
            }
        }
        /// <summary>
        /// Raises the KeyUp event
        /// </summary>
        /// <param name="e">A CellKeyEventArgs that contains the event data</param>
        public override void OnKeyUp(CellKeyEventArgs e)
        {
            base.OnKeyUp(e);

            if (e.KeyData == Keys.Space && e.Table.IsCellEditable(e.CellPos))
            {
                // get the renderer data
                CheckBoxRendererData rendererData = this.GetCheckBoxRendererData(e.Cell);

                //
                if (e.Cell.CheckState == CheckState.Checked)
                {
                    if (!e.Cell.ThreeState || !(e.Table.ColumnModel.Columns[e.Column] is CheckBoxColumn) ||
                        ((CheckBoxColumn)e.Table.ColumnModel.Columns[e.Column]).CheckStyle == CheckBoxColumnStyle.RadioButton)
                    {
                        rendererData.CheckState = CheckBoxStates.UncheckedNormal;
                        e.Cell.CheckState       = CheckState.Unchecked;
                    }
                    else
                    {
                        rendererData.CheckState = CheckBoxStates.MixedNormal;
                        e.Cell.CheckState       = CheckState.Indeterminate;
                    }
                }
                else if (e.Cell.CheckState == CheckState.Indeterminate)
                {
                    rendererData.CheckState = CheckBoxStates.UncheckedNormal;
                    e.Cell.CheckState       = CheckState.Unchecked;
                }
                else                 //if (e.Cell.CheckState == CheckState.Unchecked)
                {
                    rendererData.CheckState = CheckBoxStates.CheckedNormal;
                    e.Cell.CheckState       = CheckState.Checked;
                }

                e.Table.Invalidate(e.CellRect);
            }
        }
        /// <summary>
        /// Raises the MouseMove event
        /// </summary>
        /// <param name="e">A CellMouseEventArgs that contains the event data</param>
        public override void OnMouseMove(KellControls.KellTable.Events.CellMouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (e.Table.IsCellEditable(e.CellPos))
            {
                // get the renderer data
                CheckBoxRendererData rendererData = this.GetCheckBoxRendererData(e.Cell);

                if (this.CalcCheckRect(e.Table.TableModel.Rows[e.Row].Alignment, e.Table.ColumnModel.Columns[e.Column].Alignment).Contains(e.X, e.Y))
                {
                    if (e.Cell.CheckState == CheckState.Checked)
                    {
                        if (rendererData.CheckState == CheckBoxStates.CheckedNormal)
                        {
                            if (e.Button == MouseButtons.Left && e.Row == e.Table.LastMouseDownCell.Row && e.Column == e.Table.LastMouseDownCell.Column)
                            {
                                rendererData.CheckState = CheckBoxStates.CheckedPressed;
                            }
                            else
                            {
                                rendererData.CheckState = CheckBoxStates.CheckedHot;
                            }

                            e.Table.Invalidate(e.CellRect);
                        }
                    }
                    else if (e.Cell.CheckState == CheckState.Indeterminate)
                    {
                        if (rendererData.CheckState == CheckBoxStates.MixedNormal)
                        {
                            if (e.Button == MouseButtons.Left && e.Row == e.Table.LastMouseDownCell.Row && e.Column == e.Table.LastMouseDownCell.Column)
                            {
                                rendererData.CheckState = CheckBoxStates.MixedPressed;
                            }
                            else
                            {
                                rendererData.CheckState = CheckBoxStates.MixedHot;
                            }

                            e.Table.Invalidate(e.CellRect);
                        }
                    }
                    else                     //if (e.Cell.CheckState == CheckState.Unchecked)
                    {
                        if (rendererData.CheckState == CheckBoxStates.UncheckedNormal)
                        {
                            if (e.Button == MouseButtons.Left && e.Row == e.Table.LastMouseDownCell.Row && e.Column == e.Table.LastMouseDownCell.Column)
                            {
                                rendererData.CheckState = CheckBoxStates.UncheckedPressed;
                            }
                            else
                            {
                                rendererData.CheckState = CheckBoxStates.UncheckedHot;
                            }

                            e.Table.Invalidate(e.CellRect);
                        }
                    }
                }
                else
                {
                    if (e.Cell.CheckState == CheckState.Checked)
                    {
                        rendererData.CheckState = CheckBoxStates.CheckedNormal;
                    }
                    else if (e.Cell.CheckState == CheckState.Indeterminate)
                    {
                        rendererData.CheckState = CheckBoxStates.MixedNormal;
                    }
                    else                     //if (e.Cell.CheckState == CheckState.Unchecked)
                    {
                        rendererData.CheckState = CheckBoxStates.UncheckedNormal;
                    }

                    e.Table.Invalidate(e.CellRect);
                }
            }
        }