SharpDisplay: Migrating to new robust client scheme.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections;
13 using System.Collections.Generic;
14 using System.Collections.ObjectModel;
15 using Aga.Controls.Tree;
17 namespace OpenHardwareMonitor.GUI {
18 public class TreeModel : ITreeModel {
21 private bool forceVisible = false;
28 public TreePath GetPath(Node node) {
30 return TreePath.Empty;
32 Stack<object> stack = new Stack<object>();
33 while (node != root) {
37 return new TreePath(stack.ToArray());
41 public Collection<Node> Nodes {
42 get { return root.Nodes; }
45 private Node GetNode(TreePath treePath) {
47 foreach (object obj in treePath.FullPath) {
48 Node node = obj as Node;
49 if (node == null || node.Parent != parent)
56 public IEnumerable GetChildren(TreePath treePath) {
57 Node node = GetNode(treePath);
59 foreach (Node n in node.Nodes)
60 if (forceVisible || n.IsVisible)
67 public bool IsLeaf(TreePath treePath) {
71 public bool ForceVisible {
76 if (value != forceVisible) {
78 OnStructureChanged(root);
83 #pragma warning disable 67
84 public event EventHandler<TreeModelEventArgs> NodesChanged;
85 public event EventHandler<TreePathEventArgs> StructureChanged;
86 public event EventHandler<TreeModelEventArgs> NodesInserted;
87 public event EventHandler<TreeModelEventArgs> NodesRemoved;
88 #pragma warning restore 67
90 public void OnNodeChanged(Node parent, int index, Node node) {
91 if (NodesChanged != null && parent != null) {
92 TreePath path = GetPath(parent);
94 NodesChanged(this, new TreeModelEventArgs(
95 path, new int[] { index }, new object[] { node }));
99 public void OnStructureChanged(Node node) {
100 if (StructureChanged != null)
101 StructureChanged(this,
102 new TreeModelEventArgs(GetPath(node), new object[0]));
105 public void OnNodeInserted(Node parent, int index, Node node) {
106 if (NodesInserted != null) {
107 TreeModelEventArgs args = new TreeModelEventArgs(GetPath(parent),
108 new int[] { index }, new object[] { node });
109 NodesInserted(this, args);
114 public void OnNodeRemoved(Node parent, int index, Node node) {
115 if (NodesRemoved != null) {
116 TreeModelEventArgs args = new TreeModelEventArgs(GetPath(parent),
117 new int[] { index }, new object[] { node });
118 NodesRemoved(this, args);