Added the source code of the WinRing0 device driver.
2 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
6 namespace Aga.Controls.Tree
9 /// Provides a simple ready to use implementation of <see cref="ITreeModel"/>. Warning: this class is not optimized
10 /// to work with big amount of data. In this case create you own implementation of <c>ITreeModel</c>, and pay attention
11 /// on GetChildren and IsLeaf methods.
13 public class TreeModel : ITreeModel
21 public Collection<Node> Nodes
23 get { return _root.Nodes; }
32 public TreePath GetPath(Node node)
35 return TreePath.Empty;
38 Stack<object> stack = new Stack<object>();
44 return new TreePath(stack.ToArray());
48 public Node FindNode(TreePath path)
53 return FindNode(_root, path, 0);
56 private Node FindNode(Node root, TreePath path, int level)
58 foreach (Node node in root.Nodes)
59 if (node == path.FullPath[level])
61 if (level == path.FullPath.Length - 1)
64 return FindNode(node, path, level + 1);
69 #region ITreeModel Members
71 public System.Collections.IEnumerable GetChildren(TreePath treePath)
73 Node node = FindNode(treePath);
75 foreach (Node n in node.Nodes)
81 public bool IsLeaf(TreePath treePath)
83 Node node = FindNode(treePath);
87 throw new ArgumentException("treePath");
90 public event EventHandler<TreeModelEventArgs> NodesChanged;
91 internal void OnNodesChanged(TreeModelEventArgs args)
93 if (NodesChanged != null)
94 NodesChanged(this, args);
97 public event EventHandler<TreePathEventArgs> StructureChanged;
98 public void OnStructureChanged(TreePathEventArgs args)
100 if (StructureChanged != null)
101 StructureChanged(this, args);
104 public event EventHandler<TreeModelEventArgs> NodesInserted;
105 internal void OnNodeInserted(Node parent, int index, Node node)
107 if (NodesInserted != null)
109 TreeModelEventArgs args = new TreeModelEventArgs(GetPath(parent), new int[] { index }, new object[] { node });
110 NodesInserted(this, args);
115 public event EventHandler<TreeModelEventArgs> NodesRemoved;
116 internal void OnNodeRemoved(Node parent, int index, Node node)
118 if (NodesRemoved != null)
120 TreeModelEventArgs args = new TreeModelEventArgs(GetPath(parent), new int[] { index }, new object[] { node });
121 NodesRemoved(this, args);