using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Collections;
namespace DevComponents.AdvTree
{
/// Represents the node or tree ColumnHeader.
[ToolboxItem(false), Designer("DevComponents.AdvTree.Design.ColumnHeaderDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class ColumnHeader : Component
{
#region Private Variables
private string m_Text = "";
private ColumnWidth m_Width = null;
private bool m_Sortable = true;
private eStyleTextAlignment m_TextAlign = eStyleTextAlignment.Near;
private string m_StyleNormal = "";
private string m_StyleMouseDown = "";
private string m_StyleMouseOver = "";
private string m_ColumnName = "";
private bool m_Visible = true;
private Rectangle m_Bounds = Rectangle.Empty;
private bool m_SizeChanged = true;
private string m_Name = "";
///
/// Occurs when header size has changed due to the user resizing the column.
///
public event EventHandler HeaderSizeChanged;
internal event SortCellsEventHandler SortCells;
#endregion
#region Events
///
/// Occurs when mouse button is pressed over the column header.
///
public event MouseEventHandler MouseDown;
///
/// Occurs when mouse button is released over the column header.
///
public event MouseEventHandler MouseUp;
///
/// Occurs when header is double clicked.
///
public event EventHandler DoubleClick;
///
/// Occurs when header is clicked.
///
public event EventHandler Click;
#endregion
#region Constructor
///
/// Creates new instance of the object.
///
public ColumnHeader()
: this("")
{
}
///
/// Creates new instance of the object and initializes it with text.
///
/// Text to initialize object with.
public ColumnHeader(string text)
{
m_Text = text;
m_Width = new ColumnWidth();
m_Width.WidthChanged += new EventHandler(this.WidthChanged);
}
protected override void Dispose(bool disposing)
{
if (BarUtilities.DisposeItemImages)
{
BarUtilities.DisposeImage(ref _Image);
}
base.Dispose(disposing);
}
#endregion
#region Methods
///
/// Makes a copy of ColumnHeader object.
///
/// Returns new instance of column header object.
public virtual ColumnHeader Copy()
{
ColumnHeader c = new ColumnHeader();
c.ColumnName = this.ColumnName;
c.StyleMouseDown = this.StyleMouseDown;
c.StyleMouseOver = this.StyleMouseOver;
c.StyleNormal = this.StyleNormal;
c.Text = this.Text;
c.Visible = this.Visible;
c.Width.Absolute = this.Width.Absolute;
c.Width.Relative = this.Width.Relative;
c.Width.AutoSize = this.Width.AutoSize;
c.Width.AutoSizeMinHeader = this.Width.AutoSizeMinHeader;
c.DisplayIndex = this.DisplayIndex;
c.SortDirection = this.SortDirection;
c.SortingEnabled = this.SortingEnabled;
c.StretchToFill = this.StretchToFill;
c.Tag = this.Tag;
c.DataFieldName = this.DataFieldName;
c.DoubleClickAutoSize = this.DoubleClickAutoSize;
c.Editable = this.Editable;
c.EditorType = this.EditorType;
c.Image = this.Image;
c.ImageAlignment = this.ImageAlignment;
c.MaxInputLength = this.MaxInputLength;
c.MinimumWidth = this.MinimumWidth;
c.SortComparer = this.SortComparer;
c.SortComparerReverse = this.SortComparerReverse;
return c;
}
#endregion
#region Properties
private ColumnHeaderCollection _Parent;
internal ColumnHeaderCollection Parent
{
get { return _Parent; }
set { _Parent = value; }
}
private bool _Editable = true;
///
/// Gets or sets whether cells content in this column is editable when cell editing is enabled on tree control. Default value is true.
///
[DefaultValue(true), Category("Behavior"), Description("Indicates whether cells content in this column is editable when cell editing is enabled on tree control.")]
public bool Editable
{
get { return _Editable; }
set
{
_Editable = value;
}
}
private int _MaxInputLength = 0;
///
/// Gets or sets the maximum number of characters the user can type or paste when editing cells in this column.
///
[DefaultValue(0), Category("Behavior"), Description("Indicates maximum number of characters the user can type or paste when editing cells in this column.")]
public int MaxInputLength
{
get { return _MaxInputLength; }
set
{
_MaxInputLength = value;
}
}
///
/// Returns name of the column header that can be used to identify it from the code.
///
[Browsable(false), Category("Design"), Description("Indicates the name used to identify column header.")]
public string Name
{
get
{
if (this.Site != null)
m_Name = this.Site.Name;
return m_Name;
}
set
{
if (this.Site != null)
this.Site.Name = value;
if (value == null)
m_Name = "";
else
m_Name = value;
}
}
///
/// Returns rectangle that this column occupies. If the layout has not been performed on the column the return value will be Rectangle.Empty.
///
[Browsable(false)]
public Rectangle Bounds
{
get { return m_Bounds; }
}
///
/// Sets the column bounds.
///
internal void SetBounds(Rectangle bounds)
{
m_Bounds = bounds;
}
///
/// Gets the reference to the object that represents width of the column as either
/// absolute or relative value.
///
///
/// Set Width using Absolute or Relative properties of ColumnWidth object.
///
/// Absolute Property (DevComponents.AdvTree.ColumnWidth)
/// Relative Property (DevComponents.AdvTree.ColumnWidth)
[Browsable(true), Category("Layout"), Description("Gets or sets the width of the column."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ColumnWidth Width
{
// TODO: Add Proper TypeConverter for ColumnWidth object and test design-time support
get { return m_Width; }
}
private int _MinimumWidth = 0;
///
/// Gets or sets the minimum column width in pixels that is enforced when user is resizing the columns using mouse.
/// Default value is 0 which indicates that there is no minimum size constraint.
///
[DefaultValue(0), Category("Layout"), Description("Indicates minimum column width in pixels that is enforced when user is resizing the columns using mouse")]
public int MinimumWidth
{
get { return _MinimumWidth; }
set
{
if (value < 0) value = 0;
_MinimumWidth = value;
}
}
private bool _StretchToFill = false;
///
/// Gets or sets whether column is stretched to fill any empty space horizontally in tree when all columns consume less width than available.
/// Only one column in tree may have this property set to true and only last column with this property set will be stretched.
/// You should always set the Width for the column since Width will be used when columns consume more space in tree horizontally than available.
/// Applies to top-level columns only.
///
[DefaultValue(false), Category("Layout"), Description("Indicates whether column is stretched to fill any empty space horizontally in tree when all columns consume less width than available. Only one column in tree may have this property set to true and only last column with this property set will be stretched. You should always set the Width for the column since Width will be used when columns consume more space in tree horizontally than available. Applies to top-level columns only.")]
public bool StretchToFill
{
get { return _StretchToFill; }
set
{
if (_StretchToFill != value)
{
_StretchToFill = value;
OnSizeChanged();
}
}
}
///
/// Gets or sets the style class assigned to the column. Empty value indicates that
/// default style is used as specified on cell's parent's control.
///
///
/// Name of the style assigned to the cell or an empty string indicating that default
/// style setting from tree control is applied. Default is empty string.
///
///
/// When property is set to an empty string the style setting from parent tree
/// controls is used. ColumnStyleNormal on AdvTree control is a root style for a cell.
///
/// StyleMouseDown Property
/// StyleMouseOver Property
[Browsable(true), DefaultValue(""), Category("Style"), Description("Indicates the style class assigned to the column.")]
public string StyleNormal
{
get { return m_StyleNormal; }
set
{
if (value == null) value = "";
m_StyleNormal = value;
this.OnSizeChanged();
}
}
///
/// Gets or sets the style class assigned to the column which is applied when mouse
/// button is pressed over the header. Empty value indicates that default
/// style is used as specified on column's parent.
///
///
/// Name of the style assigned to the column or an empty string indicating that default
/// style setting from tree control is applied. Default is empty string.
///
///
/// When property is set to an empty string the style setting from parent tree
/// controls is used. ColumnStyleMouseDown on AdvTree control is a root style for a
/// cell.
///
/// StyleNormal Property
/// StyleMouseOver Property
[Browsable(true), DefaultValue(""), Category("Style"), Description("Indicates the style class assigned to the column when mouse is down.")]
public string StyleMouseDown
{
get { return m_StyleMouseDown; }
set
{
if (value == null) value = "";
m_StyleMouseDown = value;
this.OnSizeChanged();
}
}
///
/// Gets or sets the style class assigned to the column which is applied when mouse is
/// over the column. Empty value indicates that default style is used as specified on column's
/// parent control.
///
///
/// Name of the style assigned to the column or an empty string indicating that default
/// style setting from tree control is applied. Default is empty string.
///
///
/// When property is set to an empty string the style setting from parent tree
/// controls is used. ColumnStyleMouseOver on AdvTree control is a root style for a
/// cell.
///
/// StyleNormal Property
/// StyleMouseDown Property
[Browsable(true), DefaultValue(""), Category("Style"), Description("Indicates the style class assigned to the cell when mouse is over the column.")]
public string StyleMouseOver
{
get { return m_StyleMouseOver; }
set
{
if (value == null) value = "";
m_StyleMouseOver = value;
this.OnSizeChanged();
}
}
///
/// Gets or sets the name of the column in the ColumnHeaderCollection.
///
[Browsable(true), DefaultValue(""), Category("Data"), Description("Indicates the name of the column in the ColumnHeaderCollection.")]
public string ColumnName
{
get { return m_ColumnName; }
set
{
m_ColumnName = value;
}
}
///
/// Gets or sets the column caption.
///
[Browsable(true), DefaultValue(""), Category("Appearance"), Description("Indicates column caption."), Localizable(true)]
public string Text
{
get { return m_Text; }
set
{
m_Text = value;
}
}
///
/// Gets or sets whether column is visible. Hiding the header column will also hide corresponding data column.
///
[Browsable(true), DefaultValue(true), Category("Behavior"), Description("Indicates whether column is visible.")]
public bool Visible
{
get { return m_Visible; }
set
{
if (m_Visible != value)
{
m_Visible = value;
OnSizeChanged();
}
}
}
private Image _Image = null;
///
/// Gets or sets column image.
///
///
/// The image set through this property will be serialized with the column.
///
/// If you plan to use alpha-blended images we recommend using PNG-24 format
/// which supports alpha-blending. As of this writing .NET Framework 1.0 and 1.1
/// do not support alpha-blending when used through Image class.
///
///
/// Image object or null (Nothing) if no image is assigned.
[Browsable(true), DefaultValue(null), Category("Images"), Description("Indicates column image"), DevCoSerialize()]
public System.Drawing.Image Image
{
get { return _Image; }
set
{
_Image = value;
this.OnImageChanged();
}
}
private void OnImageChanged()
{
OnSizeChanged();
}
///
/// Resets Image property to it's default value (null, VB nothing).
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetImage()
{
TypeDescriptor.GetProperties(this)["Image"].SetValue(this, null);
}
private eColumnImageAlignment _ImageAlignment = eColumnImageAlignment.Left;
///
/// Gets or sets Image alignment inside of column. Default value is Left.
///
[DefaultValue(eColumnImageAlignment.Left), Category("Images"), Description("Indicates image alignment."), DevCoSerialize()]
public eColumnImageAlignment ImageAlignment
{
get { return _ImageAlignment; }
set { _ImageAlignment = value; OnSizeChanged(); }
}
private string _DataFieldName = "";
///
/// Gets or sets the data-field or property name that is used as source of data for this column when data-binding is used.
///
[DefaultValue(""), Category("Data"), Description("Indicates data-field or property name that is used as source of data for this column when data-binding is used.")]
public string DataFieldName
{
get { return _DataFieldName; }
set
{
if (value == null) value = "";
if (_DataFieldName != value)
{
_DataFieldName = value;
OnDataFieldNameChanged();
}
}
}
///
/// Called when DataFieldName property has changed.
///
protected virtual void OnDataFieldNameChanged()
{
}
private object _Tag = null;
///
/// Gets or sets additional custom data associated with the column.
///
[Browsable(false), DefaultValue(null)]
public object Tag
{
get { return _Tag; }
set { _Tag = value; }
}
private Color _CellsBackColor = Color.Empty;
///
/// Gets or sets the color of the cells background for this column.
///
[Category("Columns"), Description("Indicates color of cells background for this column.")]
public Color CellsBackColor
{
get { return _CellsBackColor; }
set
{
if (_CellsBackColor != value)
{
_CellsBackColor = value;
if (_Parent != null && _Parent.Parent != null)
_Parent.Parent.Invalidate();
}
}
}
///
/// Gets whether property should be serialized.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeCellsBackColor()
{
return !_CellsBackColor.IsEmpty;
}
///
/// Resets property to its default value.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetCellsBackColor()
{
this.CellsBackColor = Color.Empty;
}
private int _DisplayIndex = -1;
///
/// Gets or sets display index of the column. -1 indicates default value and is modified to actual display index when the column is added to a ColumnHeaderCollection.
///
///
/// A lower display index means a column will appear first (to the left) of columns with a higher display index.
/// Allowable values are from 0 to num columns - 1. (-1 is legal only as the default value and is modified to something else
/// when the column is added to a AdvTree's column collection). AdvTree enforces that no two columns have the same display index;
/// changing the display index of a column will cause the index of other columns to adjust as well.
///
[DefaultValue(-1), Category("Appearance"), Description("Indicates display index of the column. -1 indicates default value and is modified to actual display index when the column is added to a ColumnHeaderCollection.")]
public int DisplayIndex
{
get { return _DisplayIndex; }
set
{
if (value != _DisplayIndex)
{
int oldValue = _DisplayIndex;
_DisplayIndex = value;
OnDisplayIndexChanged(oldValue, value);
}
}
}
private void OnDisplayIndexChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("DisplayIndex"));
if (_Parent != null) _Parent.DisplayIndexChanged(this, newValue, oldValue);
}
private bool _SortingEnabled = true;
///
/// Gets or sets whether user can sort by this column by clicking it.
///
[DefaultValue(true), Category("Behavior"), Description("Indicates whether user can sort by this column by clicking it.")]
public bool SortingEnabled
{
get { return _SortingEnabled; }
set
{
if (value != _SortingEnabled)
{
bool oldValue = _SortingEnabled;
_SortingEnabled = value;
OnSortingEnabledChanged(oldValue, value);
}
}
}
///
/// Called when SortingEnabled property has changed.
///
/// Old property value
/// New property value
protected virtual void OnSortingEnabledChanged(bool oldValue, bool newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("SortingEnabled"));
}
private eSortDirection _SortDirection = eSortDirection.None;
///
/// Gets or sets the sort direction. Sort direction can be changed by clicking the column header if SortingEnabled=true.
///
[DefaultValue(eSortDirection.None), Category("Behavior"), Description("Indicates sort direction. Sort direction can be changed by clicking the column header if SortingEnabled=true.")]
public eSortDirection SortDirection
{
get { return _SortDirection; }
set
{
if (value != _SortDirection)
{
eSortDirection oldValue = _SortDirection;
_SortDirection = value;
OnSortDirectionChanged(oldValue, value);
}
}
}
///
/// Called when SortDirection property has changed.
///
/// Old property value
/// New property value
protected virtual void OnSortDirectionChanged(eSortDirection oldValue, eSortDirection newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("SortDirection"));
this.Invalidate();
if (_SortingEnabled)
{
if (_Parent != null) _Parent.SortDirectionUpdated(this);
if (newValue == eSortDirection.Ascending)
this.Sort(false);
else if (newValue == eSortDirection.Descending)
this.Sort(true);
}
}
///
/// Invalidates the appearance of column header.
///
private void Invalidate()
{
if (_Parent == null) return;
if (_Parent.Parent != null)
{
if (_Parent.Parent.ColumnHeaderControl != null)
{
Rectangle r = this.Bounds;
if (!this.IsFirstVisible)
{
int spacing = _Parent.Parent.CellHorizontalSpacing;
r.Width += spacing;
r.X -= spacing;
}
_Parent.Parent.ColumnHeaderControl.Invalidate(r);
}
}
else if (_Parent.ParentNode != null)
_Parent.ParentNode.Invalidate();
}
#endregion
#region Internal Implementation
///
/// Occurs after Tooltip text has changed.
///
protected virtual void OnTooltipChanged() { }
private string _Tooltip = "";
///
/// Gets/Sets informational text (tooltip) for the cell.
///
[Browsable(true), DefaultValue(""), Category("Appearance"), Description("Indicates the text that is displayed when mouse hovers over the cell."), Localizable(true)]
public string Tooltip
{
get
{
return _Tooltip;
}
set
{
if (_Tooltip == value)
return;
if (value == null) value = "";
_Tooltip = value;
if (this.ToolTipVisible)
{
if (string.IsNullOrEmpty(_Tooltip))
this.HideToolTip();
else
{
DevComponents.DotNetBar.ToolTip tooltipWindow = _ToolTipWnd;
tooltipWindow.Text = _Tooltip;
tooltipWindow.ShowToolTip();
tooltipWindow.Invalidate();
}
}
OnTooltipChanged();
}
}
///
/// Gets whether tooltip is visible or not.
///
internal protected bool ToolTipVisible
{
get
{
return (_ToolTipWnd != null);
}
}
///
/// Called when tooltip is shown and hidden.
///
/// true if tooltip is being shown otherwise false.
protected virtual void OnTooltip(bool isShown)
{
}
private DevComponents.DotNetBar.ToolTip _ToolTipWnd = null;
///
/// Shows tooltip for this item.
///
public virtual void ShowToolTip()
{
if (this.DesignMode)
return;
if (Visible)
{
AdvTree tree = this.AdvTree;
if (tree != null && !tree.ShowToolTips || !this.ShowToolTips)
return;
OnTooltip(true);
if (_Tooltip != "")
{
if (_ToolTipWnd == null)
_ToolTipWnd = new DevComponents.DotNetBar.ToolTip();
_ToolTipWnd.Style = StyleManager.GetEffectiveStyle();
_ToolTipWnd.Text = _Tooltip;
_ToolTipWnd.ReferenceRectangle = ScreenRectangle;
OnToolTipVisibleChanged(new EventArgs());
_ToolTipWnd.ShowToolTip();
}
}
}
///
/// Destroys tooltip window.
///
internal protected void HideToolTip()
{
if (_ToolTipWnd != null)
{
System.Drawing.Rectangle tipRect = _ToolTipWnd.Bounds;
tipRect.Width += 5;
tipRect.Height += 6;
OnTooltip(false);
OnToolTipVisibleChanged(new EventArgs());
try
{
if (_ToolTipWnd != null)
{
_ToolTipWnd.Hide();
_ToolTipWnd.Dispose();
_ToolTipWnd = null;
}
}
catch { }
AdvTree tree = this.AdvTree;
if (tree != null)
{
tree.Invalidate(tree.RectangleToClient(tipRect), false);
}
}
}
///
/// Occurs when item's tooltip visibility has changed.
///
[System.ComponentModel.Description("Occurs when item's tooltip visibility has changed.")]
public event EventHandler ToolTipVisibleChanged;
private void OnToolTipVisibleChanged(EventArgs eventArgs)
{
EventHandler h = ToolTipVisibleChanged;
if (h != null)
ToolTipVisibleChanged(this, eventArgs);
}
private Rectangle ScreenRectangle
{
get
{
AdvTree tree = this.AdvTree;
if (tree == null) return Rectangle.Empty;
return new Rectangle(tree.PointToScreen(this.Bounds.Location), this.Bounds.Size);
}
}
private bool _ShowToolTips = true;
///
/// Gets or sets whether tooltips are shown when mouse is over the cell when Tooltip property is set.
///
[DefaultValue(true), Category("Behavior"), Description("Indicates whether tooltips are shown when mouse is over the cell when Tooltip property is set.")]
public bool ShowToolTips
{
get { return _ShowToolTips; }
set
{
_ShowToolTips = value;
}
}
///
/// Automatically sets the column width (Width.Absolute) property based on the content of the column.
/// This will perform the one-time auto sizing of the column. To make column auto-size all the time
/// set Width.AutoSize=true.
///
public void AutoSize()
{
if (_Parent == null)
throw new InvalidOperationException("ColumnHeader is not parented.");
AdvTree tree = AdvTree;
if (tree == null)
throw new InvalidOperationException("Cannot obtain reference to parent tree control, column might not be parented.");
this.Width.AutoSize = true;
tree.RecalcLayout();
tree.Invalidate();
this.Width.SetAutoSize(false);
this.Width.SetAbsolute(this.Width.AutoSizeWidth);
OnHeaderSizeChanged(EventArgs.Empty);
}
private void OnHeaderSizeChanged(EventArgs e)
{
EventHandler h = HeaderSizeChanged;
if (h != null)
h(this, e);
}
///
/// Returns reference to AdvTree control this column belongs to.
///
[Browsable(false)]
public AdvTree AdvTree
{
get
{
if (_Parent == null) return null;
return _Parent.ParentNode == null ? _Parent.Parent : _Parent.ParentNode.TreeControl;
}
}
private bool _DoubleClickAutoSize = true;
///
/// Gets or sets whether column is automatically sized to the content when user double-clicks the column
/// on the column resize line. Column resizing must be enabled in order for this property to function.
/// Default value is true which indicates that column will be auto-sized to content when user double-clicks the
/// column resize marker.
///
[DefaultValue(true), Category("Behavior"), Description("Indicates whether column is automatically sized to content when user double-clicks the column resize marker.")]
public bool DoubleClickAutoSize
{
get { return _DoubleClickAutoSize; }
set
{
_DoubleClickAutoSize = value;
}
}
///
/// Gets or sets whether column size has changed and it's layout needs to be recalculated.
///
internal bool SizeChanged
{
get { return m_SizeChanged; }
set { m_SizeChanged = value; }
}
private void OnSizeChanged()
{
m_SizeChanged = true;
OnHeaderSizeChanged(EventArgs.Empty);
}
private void WidthChanged(object sender, EventArgs e)
{
this.OnSizeChanged();
}
private bool _IsMouseDown = false;
///
/// Gets whether mouse left button is pressed on the column.
///
[Browsable(false)]
public bool IsMouseDown
{
get { return _IsMouseDown; }
#if FRAMEWORK20
internal set
#else
set
#endif
{
if (_IsMouseDown != value)
{
_IsMouseDown = value;
OnIsMouseDownChanged();
}
}
}
private void OnIsMouseDownChanged()
{
if (_Parent != null && _Parent.ParentNode != null)
{
AdvTree tree = _Parent.ParentNode.TreeControl;
if (tree != null) tree.Invalidate(this.Bounds);
}
}
private bool _IsMouseOver = false;
///
/// Gets whether mouse is over the column.
///
[Browsable(false)]
public bool IsMouseOver
{
get { return _IsMouseOver; }
#if FRAMEWORK20
internal set
#else
set
#endif
{
_IsMouseOver = value;
this.Invalidate();
}
}
internal bool IsLastVisible = false;
internal bool IsFirstVisible = false;
///
/// Occurs when mouse is moving over the column header.
///
[Description("Occurs when mouse is moving over the column header")]
public event MouseEventHandler MouseMove;
///
/// Raises MouseMove event.
///
/// Provides event arguments.
protected virtual void OnMouseMove(MouseEventArgs e)
{
MouseEventHandler handler = MouseMove;
if (handler != null)
handler(this, e);
}
internal void InternalMouseMove(MouseEventArgs e)
{
OnMouseMove(e);
}
///
/// Occurs when mouse enters column header.
///
[Description("Occurs when mouse enters column header.")]
public event EventHandler MouseEnter;
///
/// Raises MouseEnter event.
///
/// Provides event arguments.
protected virtual void OnMouseEnter(EventArgs e)
{
EventHandler handler = MouseEnter;
if (handler != null)
handler(this, e);
}
internal void InternalMouseEnter(EventArgs e)
{
this.IsMouseOver = true;
OnMouseEnter(e);
}
///
/// Occurs when mouse leaves the column header.
///
[Description("Occurs when mouse leaves the column header.")]
public event EventHandler MouseLeave;
///
/// Raises MouseLeave event.
///
/// Provides event arguments.
protected virtual void OnMouseLeave(EventArgs e)
{
EventHandler handler = MouseLeave;
if (handler != null)
handler(this, e);
}
internal void InternalMouseLeave(EventArgs e)
{
HideToolTip();
this.IsMouseOver = false;
OnMouseLeave(e);
}
///
/// Occurs when mouse hovers over the column.
///
[Description("Occurs when mouse hovers over the column.")]
public event EventHandler MouseHover;
///
/// Raises MouseHover event.
///
/// Provides event arguments.
protected virtual void OnMouseHover(EventArgs e)
{
EventHandler handler = MouseHover;
if (handler != null)
handler(this, e);
}
internal void InternalMouseHover(EventArgs e)
{
ShowToolTip();
OnMouseHover(e);
}
internal virtual void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
HideToolTip();
if (e.Button == MouseButtons.Left) IsMouseDown = true;
MouseEventHandler eh = this.MouseDown;
if (eh != null)
eh(this, e);
}
internal virtual void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
bool wasMouseDown = IsMouseDown;
if (e.Button == MouseButtons.Left) IsMouseDown = false;
if (_SortingEnabled && wasMouseDown)
{
if (e.Button == MouseButtons.Middle && _SortDirection != eSortDirection.None)
SortDirection = eSortDirection.None;
else if (e.Button == MouseButtons.Left)
{
if (_SortDirection == eSortDirection.None || _SortDirection == eSortDirection.Descending)
SortDirection = eSortDirection.Ascending;
else
SortDirection = eSortDirection.Descending;
}
}
MouseEventHandler eh = this.MouseUp;
if (eh != null)
eh(this, e);
}
internal virtual void OnDoubleClick(EventArgs e)
{
EventHandler handler = DoubleClick;
if (handler != null) handler(this, e);
}
internal virtual void OnClick(EventArgs e)
{
EventHandler handler = Click;
if (handler != null) handler(this, e);
}
private eCellEditorType _EditorType = eCellEditorType.Default;
///
/// Gets or sets the editor type used to edit the cell. Setting this property to value other than Default
/// overrides the cell editor type specified on column cell belongs to.
///
[DefaultValue(eCellEditorType.Default), Category("Behavior"), Description("Indicates editor type used to edit the cell.")]
public eCellEditorType EditorType
{
get { return _EditorType; }
set { _EditorType = value; }
}
private bool _LastSortReverse = false;
///
/// Sort first level nodes that belong directly to this column. Calling this method repeatedly will
/// alternate between A-Z and Z-A sorting.
///
public void Sort()
{
Sort(_LastSortReverse);
_LastSortReverse = !_LastSortReverse;
}
///
/// Sort first level nodes that belong directly to this column.
///
/// true to use reverse Z-A sorting, false to sort from A-Z
public void Sort(bool reverse)
{
if (SortCells != null)
SortCells(this, new SortEventArgs(reverse, this));
}
private IComparer _SortComparer = null;
///
/// Gets or sets ascending (A-Z) column comparer used to sort nodes when this column is clicked. Your comparer will be passed to NodeCollection.Sort method and should know how to sort by appropriate column.
///
[Browsable(false), DefaultValue(null), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IComparer SortComparer
{
get { return _SortComparer; }
set
{
if (value != _SortComparer)
{
IComparer oldValue = _SortComparer;
_SortComparer = value;
OnSortComparerChanged(oldValue, value);
}
}
}
///
/// Called when SortComparer property has changed.
///
/// Old property value
/// New property value
protected virtual void OnSortComparerChanged(IComparer oldValue, IComparer newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("SortComparer"));
}
private IComparer _SortComparerReverse = null;
///
/// Gets or sets descending (Z-A) column comparer used to sort nodes when this column is clicked. Your comparer will be passed to NodeCollection.Sort method and should know how to sort by appropriate column.
///
[Browsable(false), DefaultValue(null), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public IComparer SortComparerReverse
{
get { return _SortComparerReverse; }
set
{
if (value != _SortComparerReverse)
{
IComparer oldValue = _SortComparerReverse;
_SortComparerReverse = value;
OnSortComparerReverseChanged(oldValue, value);
}
}
}
///
/// Called when SortComparerReverse property has changed.
///
/// Old property value
/// New property value
protected virtual void OnSortComparerReverseChanged(IComparer oldValue, IComparer newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("SortComparerReverse"));
}
#endregion
}
public delegate void SortCellsEventHandler(object sender, SortEventArgs e);
public class SortEventArgs : EventArgs
{
public bool ReverseSort = false;
///
/// Gets or sets whether to cancel internal sorting performed by AdvTree.
///
public bool Cancel = false;
///
/// Gets or sets the column header being sorted.
///
public ColumnHeader ColumnHeader = null;
///
/// Gets or sets the IComparer used for sorting.
///
public IComparer Comparer = null;
public SortEventArgs(bool reverse, ColumnHeader columnHeader)
{
ReverseSort = reverse;
ColumnHeader = columnHeader;
}
}
///
/// Defines column related event arguments.
///
public class ColumnEventArgs : EventArgs
{
///
/// Gets reference to the column.
///
public readonly ColumnHeader Column;
///
/// Initializes a new instance of the ColumnEventArgs class.
///
///
public ColumnEventArgs(ColumnHeader column)
{
Column = column;
}
}
///
/// Defines delegate for ColumnMoved event.
///
public delegate void ColumnMovedHandler(object sender, ColumnMovedEventArgs ea);
///
/// Defines column moved event arguments.
///
public class ColumnMovedEventArgs : ColumnEventArgs
{
///
/// Gets the column display index before the column was moved.
///
public readonly int OldColumnDisplayIndex;
///
/// Gets the column display index before the column was moved.
///
public readonly int NewColumnDisplayIndex;
///
/// Initializes a new instance of the ColumnMovedEventArgs class.
///
/// Column affected
/// Old display index
/// New display index
public ColumnMovedEventArgs(ColumnHeader column, int oldColumnDisplayIndex, int newColumnDisplayIndex)
: base(column)
{
OldColumnDisplayIndex = oldColumnDisplayIndex;
NewColumnDisplayIndex = newColumnDisplayIndex;
}
}
}