moel@345: using System; moel@345: using System.Collections.Generic; moel@345: using System.Text; moel@345: using System.Windows.Forms; moel@345: using System.Drawing; moel@345: using System.ComponentModel; moel@345: moel@345: namespace Aga.Controls.Tree.NodeControls moel@345: { moel@345: [DesignTimeVisible(false), ToolboxItem(false)] moel@345: public abstract class NodeControl : Component moel@345: { moel@345: #region Properties moel@345: moel@345: private TreeViewAdv _parent; moel@345: [Browsable(false)] moel@345: [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] moel@345: public TreeViewAdv Parent moel@345: { moel@345: get { return _parent; } moel@345: set moel@345: { moel@345: if (value != _parent) moel@345: { moel@345: if (_parent != null) moel@345: _parent.NodeControls.Remove(this); moel@345: moel@345: if (value != null) moel@345: value.NodeControls.Add(this); moel@345: } moel@345: } moel@345: } moel@345: moel@345: private IToolTipProvider _toolTipProvider; moel@345: [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] moel@345: public IToolTipProvider ToolTipProvider moel@345: { moel@345: get { return _toolTipProvider; } moel@345: set { _toolTipProvider = value; } moel@345: } moel@345: moel@345: private TreeColumn _parentColumn; moel@345: public TreeColumn ParentColumn moel@345: { moel@345: get { return _parentColumn; } moel@345: set moel@345: { moel@345: _parentColumn = value; moel@345: if (_parent != null) moel@345: _parent.FullUpdate(); moel@345: } moel@345: } moel@345: moel@345: private VerticalAlignment _verticalAlign = VerticalAlignment.Center; moel@345: [DefaultValue(VerticalAlignment.Center)] moel@345: public VerticalAlignment VerticalAlign moel@345: { moel@345: get { return _verticalAlign; } moel@345: set moel@345: { moel@345: _verticalAlign = value; moel@345: if (_parent != null) moel@345: _parent.FullUpdate(); moel@345: } moel@345: } moel@345: moel@345: private int _leftMargin = 0; moel@345: public int LeftMargin moel@345: { moel@345: get { return _leftMargin; } moel@345: set moel@345: { moel@345: if (value < 0) moel@345: throw new ArgumentOutOfRangeException(); moel@345: moel@345: _leftMargin = value; moel@345: if (_parent != null) moel@345: _parent.FullUpdate(); moel@345: } moel@345: } moel@345: #endregion moel@345: moel@345: internal virtual void AssignParent(TreeViewAdv parent) moel@345: { moel@345: _parent = parent; moel@345: } moel@345: moel@345: protected virtual Rectangle GetBounds(TreeNodeAdv node, DrawContext context) moel@345: { moel@345: Rectangle r = context.Bounds; moel@345: Size s = GetActualSize(node, context); moel@345: Size bs = new Size(r.Width - LeftMargin, Math.Min(r.Height, s.Height)); moel@345: switch (VerticalAlign) moel@345: { moel@345: case VerticalAlignment.Top: moel@345: return new Rectangle(new Point(r.X + LeftMargin, r.Y), bs); moel@345: case VerticalAlignment.Bottom: moel@345: return new Rectangle(new Point(r.X + LeftMargin, r.Bottom - s.Height), bs); moel@345: default: moel@345: return new Rectangle(new Point(r.X + LeftMargin, r.Y + (r.Height - s.Height) / 2), bs); moel@345: } moel@345: } moel@345: moel@345: protected void CheckThread() moel@345: { moel@345: if (Parent != null && Control.CheckForIllegalCrossThreadCalls) moel@345: if (Parent.InvokeRequired) moel@345: throw new InvalidOperationException("Cross-thread calls are not allowed"); moel@345: } moel@345: moel@345: public bool IsVisible(TreeNodeAdv node) moel@345: { moel@345: NodeControlValueEventArgs args = new NodeControlValueEventArgs(node); moel@345: args.Value = true; moel@345: OnIsVisibleValueNeeded(args); moel@345: return Convert.ToBoolean(args.Value); moel@345: } moel@345: moel@345: internal Size GetActualSize(TreeNodeAdv node, DrawContext context) moel@345: { moel@345: if (IsVisible(node)) moel@345: { moel@345: Size s = MeasureSize(node, context); moel@345: return new Size(s.Width + LeftMargin, s.Height); moel@345: } moel@345: else moel@345: return Size.Empty; moel@345: } moel@345: moel@345: public abstract Size MeasureSize(TreeNodeAdv node, DrawContext context); moel@345: moel@345: public abstract void Draw(TreeNodeAdv node, DrawContext context); moel@345: moel@345: public virtual string GetToolTip(TreeNodeAdv node) moel@345: { moel@345: if (ToolTipProvider != null) moel@345: return ToolTipProvider.GetToolTip(node, this); moel@345: else moel@345: return string.Empty; moel@345: } moel@345: moel@345: public virtual void MouseDown(TreeNodeAdvMouseEventArgs args) moel@345: { moel@345: } moel@345: moel@345: public virtual void MouseUp(TreeNodeAdvMouseEventArgs args) moel@345: { moel@345: } moel@345: moel@345: public virtual void MouseDoubleClick(TreeNodeAdvMouseEventArgs args) moel@345: { moel@345: } moel@345: moel@345: public virtual void KeyDown(KeyEventArgs args) moel@345: { moel@345: } moel@345: moel@345: public virtual void KeyUp(KeyEventArgs args) moel@345: { moel@345: } moel@345: moel@345: public event EventHandler IsVisibleValueNeeded; moel@345: protected virtual void OnIsVisibleValueNeeded(NodeControlValueEventArgs args) moel@345: { moel@345: if (IsVisibleValueNeeded != null) moel@345: IsVisibleValueNeeded(this, args); moel@345: } moel@345: } moel@345: }