123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using XPTable.Editors;
- using XPTable.Events;
- using XPTable.Models;
- using XPTable.Themes;
- namespace XPTable.Renderers
- {
-
-
-
- public abstract class CellRenderer : Renderer, ICellRenderer
- {
- #region Class Data
-
-
-
-
- private string format;
-
-
-
- private SolidBrush grayTextBrush;
-
-
-
- private CellPadding padding;
-
- #endregion
- #region Constructor
-
-
-
- protected CellRenderer() : base()
- {
- this.format = "";
- this.grayTextBrush = new SolidBrush(SystemColors.GrayText);
- this.padding = CellPadding.Empty;
- }
- #endregion
- #region Methods
-
-
-
-
- public override void Dispose()
- {
- base.Dispose();
- if (this.grayTextBrush != null)
- {
- this.grayTextBrush.Dispose();
- this.grayTextBrush = null;
- }
- }
-
-
-
-
-
-
- protected object GetRendererData(Cell cell)
- {
- return cell.RendererData;
- }
-
-
-
-
-
-
- protected void SetRendererData(Cell cell, object value)
- {
- cell.RendererData = value;
- }
- #endregion
- #region Properties
-
-
-
- public override Rectangle ClientRectangle
- {
- get
- {
- Rectangle client = new Rectangle(this.Bounds.Location, this.Bounds.Size);
-
-
- client.Width -= Renderer.BorderWidth;
- client.Height -= Renderer.BorderWidth;
-
- client.X += this.Padding.Left + 1;
- client.Y += this.Padding.Top;
- client.Width -= this.Padding.Left + this.Padding.Right + 1;
- client.Height -= this.Padding.Top + this.Padding.Bottom;
- return client;
- }
- }
-
-
-
- protected string Format
- {
- get
- {
- return this.format;
- }
- set
- {
- this.format = value;
- }
- }
-
-
-
- protected Brush GrayTextBrush
- {
- get
- {
- return this.grayTextBrush;
- }
- }
-
-
-
- protected CellPadding Padding
- {
- get
- {
- return this.padding;
- }
- set
- {
- this.padding = value;
- }
- }
- #endregion
- #region Events
- #region Focus
-
-
-
-
- public virtual void OnGotFocus(CellFocusEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
-
- e.Table.Invalidate(e.CellRect);
- }
-
-
-
-
- public virtual void OnLostFocus(CellFocusEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
-
- e.Table.Invalidate(e.CellRect);
- }
- #endregion
- #region Keys
-
-
-
-
- public virtual void OnKeyDown(CellKeyEventArgs e)
- {
- }
-
-
-
-
- public virtual void OnKeyUp(CellKeyEventArgs e)
- {
- }
- #endregion
- #region Mouse
- #region MouseEnter
-
-
-
-
- public virtual void OnMouseEnter(CellMouseEventArgs e)
- {
- this.Bounds = e.CellRect;
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
-
- bool tooltipActive = e.Table.ToolTip.Active;
- if (tooltipActive)
- {
- e.Table.ToolTip.Active = false;
- }
- e.Table.ResetMouseEventArgs();
- e.Table.ToolTip.SetToolTip(e.Table, e.Cell.ToolTipText);
- if (tooltipActive)
- {
- e.Table.ToolTip.Active = true;
- }
- }
- #endregion
- #region MouseLeave
-
-
-
-
- public virtual void OnMouseLeave(CellMouseEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
- }
- #endregion
- #region MouseUp
-
-
-
-
- public virtual void OnMouseUp(CellMouseEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
- }
- #endregion
- #region MouseDown
-
-
-
-
- public virtual void OnMouseDown(CellMouseEventArgs e)
- {
- if (!e.Table.Focused)
- {
- if (!(e.Table.IsEditing && e.Table.EditingCell == e.CellPos && e.Table.EditingCellEditor is IEditorUsesRendererButtons))
- {
- e.Table.Focus();
- }
- }
-
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
- }
- #endregion
- #region MouseMove
-
-
-
-
- public virtual void OnMouseMove(CellMouseEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
- }
- #endregion
- #region Click
-
-
-
-
- public virtual void OnClick(CellMouseEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
- if (e.Table.EditStartAction == EditStartAction.SingleClick && e.Table.IsCellEditable(e.CellPos))
- {
- e.Table.EditCell(e.CellPos);
- }
- }
-
-
-
-
- public virtual void OnDoubleClick(CellMouseEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell == null)
- {
- this.Padding = CellPadding.Empty;
- }
- else
- {
- this.Padding = e.Cell.Padding;
- }
- if (e.Table.EditStartAction == EditStartAction.DoubleClick && e.Table.IsCellEditable(e.CellPos))
- {
- e.Table.EditCell(e.CellPos);
- }
- }
- #endregion
- #endregion
-
- #region Paint
-
-
-
-
- public virtual void OnPaintCell(PaintCellEventArgs e)
- {
- this.Bounds = e.CellRect;
-
- if (e.Cell != null)
- {
- this.Padding = e.Cell.Padding;
- this.Alignment = e.Table.ColumnModel.Columns[e.Column].Alignment;
- this.LineAlignment = e.Table.TableModel.Rows[e.Row].Alignment;
- this.Format = e.Table.ColumnModel.Columns[e.Column].Format;
- this.Font = e.Cell.Font;
- }
- else
- {
- this.Padding = CellPadding.Empty;
- this.Alignment = ColumnAlignment.Left;
- this.LineAlignment = RowAlignment.Center;
- this.Format = "";
- this.Font = null;
- }
-
- if (this.Font == null)
- {
- this.Font = Control.DefaultFont;
- }
-
- this.OnPaintBackground(e);
-
- this.OnPaint(e);
- }
-
-
-
-
- protected virtual void OnPaintBackground(PaintCellEventArgs e)
- {
- if (e.Selected && (!e.Table.HideSelection || (e.Table.HideSelection && (e.Table.Focused || e.Table.IsEditing))))
- {
- if (e.Table.Focused || e.Table.IsEditing)
- {
- this.ForeColor = e.Table.SelectionForeColor;
- this.BackColor = e.Table.SelectionBackColor;
- }
- else
- {
- this.BackColor = e.Table.UnfocusedSelectionBackColor;
- this.ForeColor = e.Table.UnfocusedSelectionForeColor;
- }
- if (this.BackColor.A != 0)
- {
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
- else
- {
- this.ForeColor = e.Cell != null ? e.Cell.ForeColor : Color.Black;
- if (!e.Sorted || (e.Sorted && e.Table.SortedColumnBackColor.A < 255))
- {
- if (e.Cell != null)
- {
- if (e.Cell.BackColor.A < 255)
- {
- if (e.Row % 2 == 1)
- {
- if (e.Table.AlternatingRowColor.A != 0)
- {
- this.BackColor = e.Table.AlternatingRowColor;
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
-
- this.BackColor = e.Cell.BackColor;
- if (e.Cell.BackColor.A != 0)
- {
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
- else
- {
- this.BackColor = e.Cell.BackColor;
- if (e.Cell.BackColor.A != 0)
- {
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
- }
- else
- {
- if (e.Row % 2 == 1)
- {
- if (e.Table.AlternatingRowColor.A != 0)
- {
- this.BackColor = e.Table.AlternatingRowColor;
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
- }
-
- if (e.Sorted)
- {
- this.BackColor = e.Table.SortedColumnBackColor;
- if (e.Table.SortedColumnBackColor.A != 0)
- {
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
- }
- else
- {
- this.BackColor = e.Table.SortedColumnBackColor;
- e.Graphics.FillRectangle(this.BackBrush, e.CellRect);
- }
- }
- }
-
-
-
-
- protected virtual void OnPaint(PaintCellEventArgs e)
- {
-
- }
-
-
-
-
-
- protected virtual void OnPaintBorder(PaintCellEventArgs e, Pen pen)
- {
-
- e.Graphics.DrawLine(pen, e.CellRect.Left, e.CellRect.Bottom, e.CellRect.Right, e.CellRect.Bottom);
-
-
- e.Graphics.DrawLine(pen, e.CellRect.Right, e.CellRect.Top, e.CellRect.Right, e.CellRect.Bottom);
- }
- #endregion
- #endregion
- }
- }
|