Improved the moving and resizing of the gadget on multi-monitor systems. Fixed one problem where the underlying gadget window size would be reduced unrequested. Fine tuned the progress bar size in the gadget.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
41 using OpenHardwareMonitor.Hardware;
43 namespace OpenHardwareMonitor.GUI {
44 public class HardwareNode : Node {
46 private PersistentSettings settings;
47 private UnitManager unitManager;
48 private IHardware hardware;
50 private List<TypeNode> typeNodes = new List<TypeNode>();
52 public HardwareNode(IHardware hardware, PersistentSettings settings,
53 UnitManager unitManager) : base(hardware.Name)
55 this.settings = settings;
56 this.unitManager = unitManager;
57 this.hardware = hardware;
58 this.Image = HardwareTypeImage.Instance.GetImage(hardware.HardwareType);
60 typeNodes.Add(new TypeNode(SensorType.Voltage));
61 typeNodes.Add(new TypeNode(SensorType.Clock));
62 typeNodes.Add(new TypeNode(SensorType.Temperature));
63 typeNodes.Add(new TypeNode(SensorType.Load));
64 typeNodes.Add(new TypeNode(SensorType.Fan));
65 typeNodes.Add(new TypeNode(SensorType.Flow));
66 typeNodes.Add(new TypeNode(SensorType.Control));
67 typeNodes.Add(new TypeNode(SensorType.Level));
69 foreach (ISensor sensor in hardware.Sensors)
72 hardware.SensorAdded +=new SensorEventHandler(SensorAdded);
73 hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
76 public IHardware Hardware {
77 get { return hardware; }
80 private void UpdateNode(TypeNode node) {
81 if (node.Nodes.Count > 0) {
82 if (!Nodes.Contains(node)) {
84 while (i < Nodes.Count &&
85 ((TypeNode)Nodes[i]).SensorType < node.SensorType)
87 Nodes.Insert(i, node);
90 if (Nodes.Contains(node))
95 private void SensorRemoved(ISensor sensor) {
96 foreach (TypeNode typeNode in typeNodes)
97 if (typeNode.SensorType == sensor.SensorType) {
98 SensorNode sensorNode = null;
99 foreach (Node node in typeNode.Nodes) {
100 SensorNode n = node as SensorNode;
101 if (n != null && n.Sensor == sensor)
104 typeNode.Nodes.Remove(sensorNode);
105 UpdateNode(typeNode);
109 private void InsertSorted(Node node, ISensor sensor) {
111 while (i < node.Nodes.Count &&
112 ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
114 SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);
115 node.Nodes.Insert(i, sensorNode);
118 private void SensorAdded(ISensor sensor) {
119 foreach (TypeNode typeNode in typeNodes)
120 if (typeNode.SensorType == sensor.SensorType) {
121 InsertSorted(typeNode, sensor);
122 UpdateNode(typeNode);