Added a fan control sensor for ATI GPUs.
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;
40 using System.ComponentModel;
41 using System.Configuration;
45 using System.Windows.Forms;
46 using Aga.Controls.Tree;
47 using Aga.Controls.Tree.NodeControls;
48 using OpenHardwareMonitor.Hardware;
49 using OpenHardwareMonitor.Utilities;
51 namespace OpenHardwareMonitor.GUI {
52 public partial class MainForm : Form {
54 private Computer computer = new Computer();
56 private TreeModel treeModel;
57 private IDictionary<ISensor, Color> sensorPlotColors =
58 new Dictionary<ISensor, Color>();
59 private Color[] plotColorPalette;
60 private SystemTray systemTray;
61 private StartupManager startupManager = new StartupManager();
62 private UpdateVisitor updateVisitor = new UpdateVisitor();
64 private UserOption showHiddenSensors;
65 private UserOption showPlot;
66 private UserOption showValue;
67 private UserOption showMin;
68 private UserOption showMax;
69 private UserOption startMinimized;
70 private UserOption minimizeToTray;
71 private UserOption autoStart;
72 private UserOption readHddSensors;
75 InitializeComponent();
77 // set the DockStyle here, to avoid conflicts with the MainMenu
78 this.splitContainer.Dock = DockStyle.Fill;
80 int p = (int)System.Environment.OSVersion.Platform;
81 if ((p == 4) || (p == 128)) {
82 splitContainer.BorderStyle = BorderStyle.None;
83 splitContainer.Border3DStyle = Border3DStyle.Adjust;
84 splitContainer.SplitterWidth = 4;
85 treeView.BorderStyle = BorderStyle.Fixed3D;
86 plotPanel.BorderStyle = BorderStyle.Fixed3D;
89 this.Font = SystemFonts.MessageBoxFont;
90 treeView.Font = SystemFonts.MessageBoxFont;
91 plotPanel.Font = SystemFonts.MessageBoxFont;
93 nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
94 nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
95 nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
96 nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
97 nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
98 nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
99 nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
101 if (Utilities.Config.Contains("mainForm.Location.X")) {
102 int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
104 int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y);
106 this.Location = new Point(x, y);
108 StartPosition = FormStartPosition.CenterScreen;
111 ClientSize = new Size(
112 Utilities.Config.Get("mainForm.Width", 470),
113 Utilities.Config.Get("mainForm.Height", 640));
115 foreach (TreeColumn column in treeView.Columns)
116 column.Width = Math.Max(20, Math.Min(400,
117 Config.Get("treeView.Columns." + column.Header + ".Width",
120 treeModel = new TreeModel();
121 root = new Node(System.Environment.MachineName);
122 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
124 treeModel.Nodes.Add(root);
125 treeView.Model = treeModel;
127 systemTray = new SystemTray(computer);
128 systemTray.HideShowCommand += hideShowClick;
129 systemTray.ExitCommand += exitClick;
131 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
132 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
135 timer.Enabled = true;
137 plotColorPalette = new Color[13];
138 plotColorPalette[0] = Color.Blue;
139 plotColorPalette[1] = Color.OrangeRed;
140 plotColorPalette[2] = Color.Green;
141 plotColorPalette[3] = Color.LightSeaGreen;
142 plotColorPalette[4] = Color.Goldenrod;
143 plotColorPalette[5] = Color.DarkViolet;
144 plotColorPalette[6] = Color.YellowGreen;
145 plotColorPalette[7] = Color.SaddleBrown;
146 plotColorPalette[8] = Color.RoyalBlue;
147 plotColorPalette[9] = Color.DeepPink;
148 plotColorPalette[10] = Color.MediumSeaGreen;
149 plotColorPalette[11] = Color.Olive;
150 plotColorPalette[12] = Color.Firebrick;
152 showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem);
153 showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
154 treeModel.ForceVisible = showHiddenSensors.Value;
157 showPlot = new UserOption("plotMenuItem", false, plotMenuItem);
158 showPlot.Changed += delegate(object sender, EventArgs e) {
159 splitContainer.Panel2Collapsed = !showPlot.Value;
160 treeView.Invalidate();
163 showValue = new UserOption("valueMenuItem", true, valueMenuItem);
164 showValue.Changed += delegate(object sender, EventArgs e) {
165 treeView.Columns[1].IsVisible = showValue.Value;
168 showMin = new UserOption("minMenuItem", false, minMenuItem);
169 showMin.Changed += delegate(object sender, EventArgs e) {
170 treeView.Columns[2].IsVisible = showMin.Value;
173 showMax = new UserOption("maxMenuItem", true, maxMenuItem);
174 showMax.Changed += delegate(object sender, EventArgs e) {
175 treeView.Columns[3].IsVisible = showMax.Value;
178 startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem);
180 minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem);
181 minimizeToTray.Changed += delegate(object sender, EventArgs e) {
182 systemTray.IsMainIconEnabled = minimizeToTray.Value;
185 autoStart = new UserOption(null, startupManager.Startup, startupMenuItem);
186 autoStart.Changed += delegate(object sender, EventArgs e) {
187 startupManager.Startup = autoStart.Value; ;
190 readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem);
191 readHddSensors.Changed += delegate(object sender, EventArgs e) {
192 computer.HDDEnabled = readHddSensors.Value;
193 UpdatePlotSelection(null, null);
196 celciusMenuItem.Checked =
197 UnitManager.TemperatureUnit == TemperatureUnit.Celcius;
198 fahrenheitMenuItem.Checked = !celciusMenuItem.Checked;
200 startupMenuItem.Visible = startupManager.IsAvailable;
202 if (startMinMenuItem.Checked) {
203 if (!minTrayMenuItem.Checked) {
204 WindowState = FormWindowState.Minimized;
211 // Create a handle, otherwise calling Close() does not fire FormClosed
212 IntPtr handle = Handle;
214 // Make sure the settings are saved when the user logs off
215 Microsoft.Win32.SystemEvents.SessionEnded +=
216 delegate(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
221 private void SubHardwareAdded(IHardware hardware, Node node) {
222 Node hardwareNode = new HardwareNode(hardware);
223 node.Nodes.Add(hardwareNode);
224 foreach (IHardware subHardware in hardware.SubHardware)
225 SubHardwareAdded(subHardware, hardwareNode);
228 private void HardwareAdded(IHardware hardware) {
229 Node hardwareNode = new HardwareNode(hardware);
230 root.Nodes.Add(hardwareNode);
231 foreach (IHardware subHardware in hardware.SubHardware)
232 SubHardwareAdded(subHardware, hardwareNode);
235 private void HardwareRemoved(IHardware hardware) {
236 List<Node> nodesToRemove = new List<Node>();
237 foreach (Node node in root.Nodes) {
238 HardwareNode hardwareNode = node as HardwareNode;
239 if (hardwareNode != null && hardwareNode.Hardware == hardware)
240 nodesToRemove.Add(node);
242 foreach (Node node in nodesToRemove)
243 root.Nodes.Remove(node);
246 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
247 Node node = e.Node.Tag as Node;
250 if (node.IsVisible) {
251 SensorNode sensorNode = node as SensorNode;
252 if (plotMenuItem.Checked && sensorNode != null &&
253 sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
256 e.TextColor = Color.DarkGray;
261 private void UpdatePlotSelection(object sender,
264 List<ISensor> selected = new List<ISensor>();
265 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
267 foreach (TreeNodeAdv node in treeView.AllNodes) {
268 SensorNode sensorNode = node.Tag as SensorNode;
269 if (sensorNode != null &&
270 sensorNode.Sensor.SensorType == SensorType.Temperature) {
271 if (sensorNode.Plot) {
272 colors.Add(sensorNode.Sensor,
273 plotColorPalette[colorIndex % plotColorPalette.Length]);
274 selected.Add(sensorNode.Sensor);
279 sensorPlotColors = colors;
280 plotPanel.SetSensors(selected, colors);
283 private void nodeTextBoxText_EditorShowing(object sender, CancelEventArgs e)
285 e.Cancel = !(treeView.CurrentNode != null &&
286 treeView.CurrentNode.Tag is SensorNode);
289 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
290 NodeControlValueEventArgs e) {
291 SensorNode node = e.Node.Tag as SensorNode;
292 e.Value = (node != null) &&
293 (node.Sensor.SensorType == SensorType.Temperature) &&
294 plotMenuItem.Checked;
297 private void exitClick(object sender, EventArgs e) {
301 private void timer_Tick(object sender, EventArgs e) {
302 computer.Accept(updateVisitor);
303 treeView.Invalidate();
304 plotPanel.Invalidate();
308 private void SaveConfiguration() {
309 if (WindowState != FormWindowState.Minimized) {
310 Config.Set("mainForm.Location.X", Location.X);
311 Config.Set("mainForm.Location.Y", Location.Y);
312 Config.Set("mainForm.Width", ClientSize.Width);
313 Config.Set("mainForm.Height", ClientSize.Height);
316 foreach (TreeColumn column in treeView.Columns)
317 Config.Set("treeView.Columns." + column.Header + ".Width",
323 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
327 timer.Enabled = false;
328 systemTray.Dispose();
332 private void aboutMenuItem_Click(object sender, EventArgs e) {
333 new AboutBox().ShowDialog();
336 private void treeView_Click(object sender, EventArgs e) {
338 MouseEventArgs m = e as MouseEventArgs;
339 if (m == null || m.Button != MouseButtons.Right)
342 NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
343 treeView.SelectedNode = info.Node;
344 if (info.Node != null) {
345 SensorNode node = info.Node.Tag as SensorNode;
346 if (node != null && node.Sensor != null) {
347 sensorContextMenu.MenuItems.Clear();
348 if (node.Sensor.Parameters.Length > 0) {
349 MenuItem item = new MenuItem("Parameters...");
350 item.Click += delegate(object obj, EventArgs args) {
351 ShowParameterForm(node.Sensor);
353 sensorContextMenu.MenuItems.Add(item);
355 if (nodeTextBoxText.EditEnabled) {
356 MenuItem item = new MenuItem("Rename");
357 item.Click += delegate(object obj, EventArgs args) {
358 nodeTextBoxText.BeginEdit();
360 sensorContextMenu.MenuItems.Add(item);
362 if (node.IsVisible) {
363 MenuItem item = new MenuItem("Hide");
364 item.Click += delegate(object obj, EventArgs args) {
365 node.IsVisible = false;
367 sensorContextMenu.MenuItems.Add(item);
369 MenuItem item = new MenuItem("Unhide");
370 item.Click += delegate(object obj, EventArgs args) {
371 node.IsVisible = true;
373 sensorContextMenu.MenuItems.Add(item);
375 if (systemTray.Contains(node.Sensor)) {
376 MenuItem item = new MenuItem("Remove From Tray");
377 item.Click += delegate(object obj, EventArgs args) {
378 systemTray.Remove(node.Sensor);
380 sensorContextMenu.MenuItems.Add(item);
382 MenuItem item = new MenuItem("Add To Tray");
383 item.Click += delegate(object obj, EventArgs args) {
384 systemTray.Add(node.Sensor, true);
386 sensorContextMenu.MenuItems.Add(item);
388 sensorContextMenu.Show(treeView, new Point(m.X, m.Y));
393 private void saveReportMenuItem_Click(object sender, EventArgs e) {
394 string report = computer.GetReport();
395 if (saveFileDialog.ShowDialog() == DialogResult.OK) {
396 using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
402 private void SysTrayHideShow() {
408 protected override void WndProc(ref Message m) {
409 const int WM_SYSCOMMAND = 0x112;
410 const int SC_MINIMIZE = 0xF020;
411 if (minimizeToTray.Value &&
412 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
419 private void hideShowClick(object sender, EventArgs e) {
423 private void removeMenuItem_Click(object sender, EventArgs e) {
424 MenuItem item = sender as MenuItem;
428 ISensor sensor = item.Parent.Tag as ISensor;
432 systemTray.Remove(sensor);
435 private void ShowParameterForm(ISensor sensor) {
436 ParameterForm form = new ParameterForm();
437 form.Parameters = sensor.Parameters;
438 form.captionLabel.Text = sensor.Name;
442 private void treeView_NodeMouseDoubleClick(object sender,
443 TreeNodeAdvMouseEventArgs e) {
444 SensorNode node = e.Node.Tag as SensorNode;
445 if (node != null && node.Sensor != null &&
446 node.Sensor.Parameters.Length > 0) {
447 ShowParameterForm(node.Sensor);
451 private void celciusMenuItem_Click(object sender, EventArgs e) {
452 celciusMenuItem.Checked = true;
453 fahrenheitMenuItem.Checked = false;
454 UnitManager.TemperatureUnit = TemperatureUnit.Celcius;
457 private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
458 celciusMenuItem.Checked = false;
459 fahrenheitMenuItem.Checked = true;
460 UnitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
463 private void sumbitReportMenuItem_Click(object sender, EventArgs e)
465 ReportForm form = new ReportForm();
466 form.Report = computer.GetReport();
470 private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
471 computer.Accept(new SensorVisitor(delegate(ISensor sensor) {