#region Imports using DPumpHydr.WinFrmUI.RLT.Util; using System; using System.Drawing; using static System.Net.Mime.MediaTypeNames; #endregion namespace DPumpHydr.WinFrmUI.Base { #region StepTreeNode public class StepTreeNode { public StepTreeNode(StepTreeView ParentTree, StepTreeNodePara paras) { this.Nodes = new ObservableList(); this.Text = paras.Caption; this.NodePara = paras; this._parentTree = ParentTree; } #region Event Region //public event EventHandler> ItemsAdded; //public event EventHandler> ItemsRemoved; //public event EventHandler TextChanged; public event Action NodeExpanded; public event Action NodeCollapsed; #endregion #region Field Region private string _text; private StepTreeView _parentTree; private ObservableList _nodes; private bool _expanded; #endregion #region Property Region public string Text { get => _text; set { if (_text == value) { return; } _text = value; } } public Rectangle ExpandArea { get; set; } public Rectangle IconArea { get; set; } public Rectangle TextArea { get; set; } public Rectangle FullArea { get; set; } public bool IsHover { get; set; } = false; public System.Drawing.Image Icon { get; set; } public bool Expanded { get => _expanded; set { if (_expanded == value) { return; } if (value == true && Nodes.Count == 0) { return; } _expanded = value; if (_expanded) { NodeExpanded?.Invoke(this); } else { NodeCollapsed?.Invoke(this); } } } public ObservableList Nodes { get => _nodes; set { _nodes = value; } } public bool IsRoot { get; set; } public StepTreeView ParentTree { get => _parentTree; set { if (_parentTree == value) { return; } _parentTree = value; foreach (StepTreeNode node in Nodes) { node.ParentTree = _parentTree; } } } public StepTreeNode ParentNode { get; set; } public bool Odd { get; set; } public object NodeType { get; set; } public StepTreeNodePara NodePara { get; set; } public string FullPath { get { StepTreeNode parent = ParentNode; string path = Text; while (parent != null) { path = string.Format("{0}{1}{2}", parent.Text, "\\", path); parent = parent.ParentNode; } return path; } } public StepTreeNode PrevVisibleNode { get; set; } public StepTreeNode NextVisibleNode { get; set; } public int VisibleIndex { get; set; } public bool IsNodeAncestor(StepTreeNode node) { StepTreeNode parent = ParentNode; while (parent != null) { if (parent == node) { return true; } parent = parent.ParentNode; } return false; } #endregion #region Method Region //public void Remove() //{ // if (ParentNode != null) // { // ParentNode.Nodes.Remove(this); // } // else // { // ParentTree.Nodes.Remove(this); // } //} public void EnsureVisible() { StepTreeNode parent = ParentNode; while (parent != null) { parent.Expanded = true; parent = parent.ParentNode; } } #endregion } #endregion }