123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- using XPTable.Events;
- namespace XPTable.Renderers
- {
-
-
-
- public abstract class HeaderRenderer : Renderer, IHeaderRenderer
- {
- #region Constructor
-
-
-
-
- protected HeaderRenderer() : base()
- {
- this.StringFormat.Alignment = StringAlignment.Near;
- }
- #endregion
- #region Methods
-
-
-
-
-
-
- protected Rectangle CalcImageRect()
- {
- Rectangle imageRect = this.ClientRectangle;
- if (imageRect.Width > 16)
- {
- imageRect.Width = 16;
- }
- if (imageRect.Height > 16)
- {
- imageRect.Height = 16;
- imageRect.Y += (this.ClientRectangle.Height - imageRect.Height) / 2;
- }
- return imageRect;
- }
-
-
-
-
- protected Rectangle CalcSortArrowRect()
- {
- Rectangle arrowRect = this.ClientRectangle;
- arrowRect.Width = 12;
- arrowRect.X = this.ClientRectangle.Right - arrowRect.Width;
- return arrowRect;
- }
- #endregion
-
- #region Properties
-
-
-
-
- [Browsable(false)]
- public override Rectangle ClientRectangle
- {
- get
- {
- Rectangle client = new Rectangle(this.Bounds.Location, this.Bounds.Size);
-
-
- client.Inflate(-2, -2);
- return client;
- }
- }
- #endregion
- #region Events
- #region Mouse
- #region MouseEnter
-
-
-
-
- public virtual void OnMouseEnter(HeaderMouseEventArgs e)
- {
- this.Bounds = e.HeaderRect;
- bool tooltipActive = e.Table.ToolTip.Active;
- if (tooltipActive)
- {
- e.Table.ToolTip.Active = false;
- }
- e.Table.ResetMouseEventArgs();
- e.Table.ToolTip.SetToolTip(e.Table, e.Column.ToolTipText);
- if (tooltipActive)
- {
- e.Table.ToolTip.Active = true;
- }
- }
- #endregion
- #region MouseLeave
-
-
-
-
- public virtual void OnMouseLeave(HeaderMouseEventArgs e)
- {
- this.Bounds = e.HeaderRect;
- }
- #endregion
- #region MouseUp
-
-
-
-
- public virtual void OnMouseUp(HeaderMouseEventArgs e)
- {
- this.Bounds = e.HeaderRect;
- }
- #endregion
- #region MouseDown
-
-
-
-
- public virtual void OnMouseDown(HeaderMouseEventArgs e)
- {
- if (!e.Table.Focused)
- {
- e.Table.Focus();
- }
-
- this.Bounds = e.HeaderRect;
- }
- #endregion
- #region MouseMove
-
-
-
-
- public virtual void OnMouseMove(HeaderMouseEventArgs e)
- {
- this.Bounds = e.HeaderRect;
- }
- #endregion
- #region Click
-
-
-
-
- public virtual void OnClick(HeaderMouseEventArgs e)
- {
- this.Bounds = e.HeaderRect;
- }
-
-
-
-
- public virtual void OnDoubleClick(HeaderMouseEventArgs e)
- {
- this.Bounds = e.HeaderRect;
- }
- #endregion
- #endregion
-
- #region Paint
-
-
-
-
- public virtual void OnPaintHeader(PaintHeaderEventArgs e)
- {
-
- this.OnPaintBackground(e);
-
- this.OnPaint(e);
- }
-
-
-
-
- protected virtual void OnPaintBackground(PaintHeaderEventArgs e)
- {
-
- }
-
-
-
-
- protected virtual void OnPaint(PaintHeaderEventArgs e)
- {
-
- }
-
-
-
-
-
-
-
-
-
-
-
- protected void DrawColumnHeaderImage(Graphics g, Image image, Rectangle imageRect, bool enabled)
- {
- if (enabled)
- {
- g.DrawImage(image, imageRect);
- }
- else
- {
- using (Image im = new Bitmap(image, imageRect.Width, imageRect.Height))
- {
- ControlPaint.DrawImageDisabled(g, im, imageRect.X, imageRect.Y, this.BackBrush.Color);
- }
- }
- }
-
-
-
-
-
-
-
-
-
- protected virtual void DrawSortArrow(Graphics g, Rectangle drawRect, SortOrder direction, bool enabled)
- {
- if (direction != SortOrder.None)
- {
- using (Font font = new Font("Marlett", 9f))
- {
- using (StringFormat format = new StringFormat())
- {
- format.Alignment = StringAlignment.Far;
- format.LineAlignment = StringAlignment.Center;
- if (direction == SortOrder.Ascending)
- {
- if (enabled)
- {
- g.DrawString("t", font, SystemBrushes.ControlDarkDark, drawRect, format);
- }
- else
- {
- using (SolidBrush brush = new SolidBrush(SystemPens.GrayText.Color))
- {
- g.DrawString("t", font, brush, drawRect, format);
- }
- }
- }
- else
- {
- if (enabled)
- {
- g.DrawString("u", font, SystemBrushes.ControlDarkDark, drawRect, format);
- }
- else
- {
- using (SolidBrush brush = new SolidBrush(SystemPens.GrayText.Color))
- {
- g.DrawString("u", font, brush, drawRect, format);
- }
- }
- }
- }
- }
- }
- }
- #endregion
- #endregion
- }
- }
|