Added experimental support for the Nuvoton NCT6791D super I/O chip.
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-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
8 Copyright (C) 2010 Paul Werelds <paul@werelds.net>
9 Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
14 using System.Collections.Generic;
15 using System.Collections.ObjectModel;
16 using System.ComponentModel;
19 using System.Reflection;
20 using System.Windows.Forms;
21 using Aga.Controls.Tree;
22 using Aga.Controls.Tree.NodeControls;
23 using OpenHardwareMonitor.Hardware;
24 using OpenHardwareMonitor.WMI;
25 using OpenHardwareMonitor.Utilities;
27 namespace OpenHardwareMonitor.GUI {
28 public partial class MainForm : Form {
30 private PersistentSettings settings;
31 private UnitManager unitManager;
32 private Computer computer;
34 private TreeModel treeModel;
35 private IDictionary<ISensor, Color> sensorPlotColors =
36 new Dictionary<ISensor, Color>();
37 private Color[] plotColorPalette;
38 private SystemTray systemTray;
39 private StartupManager startupManager = new StartupManager();
40 private UpdateVisitor updateVisitor = new UpdateVisitor();
41 private SensorGadget gadget;
42 private Form plotForm;
43 private PlotPanel plotPanel;
45 private UserOption showHiddenSensors;
46 private UserOption showPlot;
47 private UserOption showValue;
48 private UserOption showMin;
49 private UserOption showMax;
50 private UserOption startMinimized;
51 private UserOption minimizeToTray;
52 private UserOption minimizeOnClose;
53 private UserOption autoStart;
55 private UserOption readMainboardSensors;
56 private UserOption readCpuSensors;
57 private UserOption readRamSensors;
58 private UserOption readGpuSensors;
59 private UserOption readFanControllersSensors;
60 private UserOption readHddSensors;
62 private UserOption showGadget;
63 private UserRadioGroup plotLocation;
64 private WmiProvider wmiProvider;
66 private UserOption runWebServer;
67 private HttpServer server;
69 private bool selectionDragging = false;
72 InitializeComponent();
74 // check if the OpenHardwareMonitorLib assembly has the correct version
75 if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
76 Assembly.GetExecutingAssembly().GetName().Version) {
78 "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
79 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
83 this.settings = new PersistentSettings();
84 this.settings.Load(Path.ChangeExtension(
85 Application.ExecutablePath, ".config"));
87 this.unitManager = new UnitManager(settings);
89 // make sure the buffers used for double buffering are not disposed
90 // after each draw call
91 BufferedGraphicsManager.Current.MaximumBuffer =
92 Screen.PrimaryScreen.Bounds.Size;
94 // set the DockStyle here, to avoid conflicts with the MainMenu
95 this.splitContainer.Dock = DockStyle.Fill;
97 this.Font = SystemFonts.MessageBoxFont;
98 treeView.Font = SystemFonts.MessageBoxFont;
100 plotPanel = new PlotPanel(settings, unitManager);
101 plotPanel.Font = SystemFonts.MessageBoxFont;
102 plotPanel.Dock = DockStyle.Fill;
104 nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
105 nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
106 nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
107 nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
108 nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
109 nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
111 foreach (TreeColumn column in treeView.Columns)
112 column.Width = Math.Max(20, Math.Min(400,
113 settings.GetValue("treeView.Columns." + column.Header + ".Width",
116 treeModel = new TreeModel();
117 root = new Node(System.Environment.MachineName);
118 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
120 treeModel.Nodes.Add(root);
121 treeView.Model = treeModel;
123 this.computer = new Computer(settings);
125 systemTray = new SystemTray(computer, settings, unitManager);
126 systemTray.HideShowCommand += hideShowClick;
127 systemTray.ExitCommand += exitClick;
129 int p = (int)Environment.OSVersion.Platform;
130 if ((p == 4) || (p == 128)) { // Unix
131 treeView.RowHeight = Math.Max(treeView.RowHeight, 18);
132 splitContainer.BorderStyle = BorderStyle.None;
133 splitContainer.Border3DStyle = Border3DStyle.Adjust;
134 splitContainer.SplitterWidth = 4;
135 treeView.BorderStyle = BorderStyle.Fixed3D;
136 plotPanel.BorderStyle = BorderStyle.Fixed3D;
137 gadgetMenuItem.Visible = false;
138 minCloseMenuItem.Visible = false;
139 minTrayMenuItem.Visible = false;
140 startMinMenuItem.Visible = false;
142 treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);
144 gadget = new SensorGadget(computer, settings, unitManager);
145 gadget.HideShowCommand += hideShowClick;
147 wmiProvider = new WmiProvider(computer);
150 plotColorPalette = new Color[13];
151 plotColorPalette[0] = Color.Blue;
152 plotColorPalette[1] = Color.OrangeRed;
153 plotColorPalette[2] = Color.Green;
154 plotColorPalette[3] = Color.LightSeaGreen;
155 plotColorPalette[4] = Color.Goldenrod;
156 plotColorPalette[5] = Color.DarkViolet;
157 plotColorPalette[6] = Color.YellowGreen;
158 plotColorPalette[7] = Color.SaddleBrown;
159 plotColorPalette[8] = Color.RoyalBlue;
160 plotColorPalette[9] = Color.DeepPink;
161 plotColorPalette[10] = Color.MediumSeaGreen;
162 plotColorPalette[11] = Color.Olive;
163 plotColorPalette[12] = Color.Firebrick;
165 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
166 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
170 timer.Enabled = true;
172 showHiddenSensors = new UserOption("hiddenMenuItem", false,
173 hiddenMenuItem, settings);
174 showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
175 treeModel.ForceVisible = showHiddenSensors.Value;
178 showValue = new UserOption("valueMenuItem", true, valueMenuItem,
180 showValue.Changed += delegate(object sender, EventArgs e) {
181 treeView.Columns[1].IsVisible = showValue.Value;
184 showMin = new UserOption("minMenuItem", false, minMenuItem, settings);
185 showMin.Changed += delegate(object sender, EventArgs e) {
186 treeView.Columns[2].IsVisible = showMin.Value;
189 showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings);
190 showMax.Changed += delegate(object sender, EventArgs e) {
191 treeView.Columns[3].IsVisible = showMax.Value;
194 startMinimized = new UserOption("startMinMenuItem", false,
195 startMinMenuItem, settings);
197 minimizeToTray = new UserOption("minTrayMenuItem", true,
198 minTrayMenuItem, settings);
199 minimizeToTray.Changed += delegate(object sender, EventArgs e) {
200 systemTray.IsMainIconEnabled = minimizeToTray.Value;
203 minimizeOnClose = new UserOption("minCloseMenuItem", false,
204 minCloseMenuItem, settings);
206 autoStart = new UserOption(null, startupManager.Startup,
207 startupMenuItem, settings);
208 autoStart.Changed += delegate(object sender, EventArgs e) {
210 startupManager.Startup = autoStart.Value;
211 } catch (InvalidOperationException) {
212 MessageBox.Show("Updating the auto-startup option failed.", "Error",
213 MessageBoxButtons.OK, MessageBoxIcon.Error);
214 autoStart.Value = startupManager.Startup;
218 readMainboardSensors = new UserOption("mainboardMenuItem", true,
219 mainboardMenuItem, settings);
220 readMainboardSensors.Changed += delegate(object sender, EventArgs e) {
221 computer.MainboardEnabled = readMainboardSensors.Value;
224 readCpuSensors = new UserOption("cpuMenuItem", true,
225 cpuMenuItem, settings);
226 readCpuSensors.Changed += delegate(object sender, EventArgs e) {
227 computer.CPUEnabled = readCpuSensors.Value;
230 readRamSensors = new UserOption("ramMenuItem", true,
231 ramMenuItem, settings);
232 readRamSensors.Changed += delegate(object sender, EventArgs e) {
233 computer.RAMEnabled = readRamSensors.Value;
236 readGpuSensors = new UserOption("gpuMenuItem", true,
237 gpuMenuItem, settings);
238 readGpuSensors.Changed += delegate(object sender, EventArgs e) {
239 computer.GPUEnabled = readGpuSensors.Value;
242 readFanControllersSensors = new UserOption("fanControllerMenuItem", true,
243 fanControllerMenuItem, settings);
244 readFanControllersSensors.Changed += delegate(object sender, EventArgs e) {
245 computer.FanControllerEnabled = readFanControllersSensors.Value;
248 readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
250 readHddSensors.Changed += delegate(object sender, EventArgs e) {
251 computer.HDDEnabled = readHddSensors.Value;
254 showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
256 showGadget.Changed += delegate(object sender, EventArgs e) {
258 gadget.Visible = showGadget.Value;
261 celsiusMenuItem.Checked =
262 unitManager.TemperatureUnit == TemperatureUnit.Celsius;
263 fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;
265 server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085));
266 if (server.PlatformNotSupported) {
267 webMenuItemSeparator.Visible = false;
268 webMenuItem.Visible = false;
271 runWebServer = new UserOption("runWebServerMenuItem", false,
272 runWebServerMenuItem, settings);
273 runWebServer.Changed += delegate(object sender, EventArgs e) {
274 if (runWebServer.Value)
275 server.StartHTTPListener();
277 server.StopHTTPListener();
280 InitializePlotForm();
282 startupMenuItem.Visible = startupManager.IsAvailable;
284 if (startMinMenuItem.Checked) {
285 if (!minTrayMenuItem.Checked) {
286 WindowState = FormWindowState.Minimized;
293 // Create a handle, otherwise calling Close() does not fire FormClosed
294 IntPtr handle = Handle;
296 // Make sure the settings are saved when the user logs off
297 Microsoft.Win32.SystemEvents.SessionEnded += delegate {
300 if (runWebServer.Value)
305 private void InitializePlotForm() {
306 plotForm = new Form();
307 plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
308 plotForm.ShowInTaskbar = false;
309 plotForm.StartPosition = FormStartPosition.Manual;
310 this.AddOwnedForm(plotForm);
311 plotForm.Bounds = new Rectangle {
312 X = settings.GetValue("plotForm.Location.X", -100000),
313 Y = settings.GetValue("plotForm.Location.Y", 100),
314 Width = settings.GetValue("plotForm.Width", 600),
315 Height = settings.GetValue("plotForm.Height", 400)
318 showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
319 plotLocation = new UserRadioGroup("plotLocation", 0,
320 new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
323 showPlot.Changed += delegate(object sender, EventArgs e) {
324 if (plotLocation.Value == 0) {
325 if (showPlot.Value && this.Visible)
330 splitContainer.Panel2Collapsed = !showPlot.Value;
332 treeView.Invalidate();
334 plotLocation.Changed += delegate(object sender, EventArgs e) {
335 switch (plotLocation.Value) {
337 splitContainer.Panel2.Controls.Clear();
338 splitContainer.Panel2Collapsed = true;
339 plotForm.Controls.Add(plotPanel);
340 if (showPlot.Value && this.Visible)
344 plotForm.Controls.Clear();
346 splitContainer.Orientation = Orientation.Horizontal;
347 splitContainer.Panel2.Controls.Add(plotPanel);
348 splitContainer.Panel2Collapsed = !showPlot.Value;
351 plotForm.Controls.Clear();
353 splitContainer.Orientation = Orientation.Vertical;
354 splitContainer.Panel2.Controls.Add(plotPanel);
355 splitContainer.Panel2Collapsed = !showPlot.Value;
360 plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) {
361 if (e.CloseReason == CloseReason.UserClosing) {
362 // just switch off the plotting when the user closes the form
363 if (plotLocation.Value == 0) {
364 showPlot.Value = false;
370 EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
371 if (plotForm.WindowState != FormWindowState.Minimized) {
372 settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
373 settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
374 settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
375 settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
378 plotForm.Move += moveOrResizePlotForm;
379 plotForm.Resize += moveOrResizePlotForm;
381 plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
382 Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
383 Screen screen = Screen.FromRectangle(bounds);
384 Rectangle intersection =
385 Rectangle.Intersect(screen.WorkingArea, bounds);
386 if (intersection.Width < Math.Min(16, bounds.Width) ||
387 intersection.Height < Math.Min(16, bounds.Height)) {
388 plotForm.Location = new Point(
389 screen.WorkingArea.Width / 2 - bounds.Width / 2,
390 screen.WorkingArea.Height / 2 - bounds.Height / 2);
394 this.VisibleChanged += delegate(object sender, EventArgs e) {
395 if (this.Visible && showPlot.Value && plotLocation.Value == 0)
402 private void InsertSorted(Collection<Node> nodes, HardwareNode node) {
404 while (i < nodes.Count && nodes[i] is HardwareNode &&
405 ((HardwareNode)nodes[i]).Hardware.HardwareType <
406 node.Hardware.HardwareType)
408 nodes.Insert(i, node);
411 private void SubHardwareAdded(IHardware hardware, Node node) {
412 HardwareNode hardwareNode =
413 new HardwareNode(hardware, settings, unitManager);
414 hardwareNode.PlotSelectionChanged += PlotSelectionChanged;
416 InsertSorted(node.Nodes, hardwareNode);
418 foreach (IHardware subHardware in hardware.SubHardware)
419 SubHardwareAdded(subHardware, hardwareNode);
422 private void HardwareAdded(IHardware hardware) {
423 SubHardwareAdded(hardware, root);
424 PlotSelectionChanged(this, null);
427 private void HardwareRemoved(IHardware hardware) {
428 List<HardwareNode> nodesToRemove = new List<HardwareNode>();
429 foreach (Node node in root.Nodes) {
430 HardwareNode hardwareNode = node as HardwareNode;
431 if (hardwareNode != null && hardwareNode.Hardware == hardware)
432 nodesToRemove.Add(hardwareNode);
434 foreach (HardwareNode hardwareNode in nodesToRemove) {
435 root.Nodes.Remove(hardwareNode);
436 hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
438 PlotSelectionChanged(this, null);
441 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
442 Node node = e.Node.Tag as Node;
445 if (node.IsVisible) {
446 SensorNode sensorNode = node as SensorNode;
447 if (plotMenuItem.Checked && sensorNode != null &&
448 sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
451 e.TextColor = Color.DarkGray;
456 private void PlotSelectionChanged(object sender, EventArgs e) {
457 List<ISensor> selected = new List<ISensor>();
458 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
460 foreach (TreeNodeAdv node in treeView.AllNodes) {
461 SensorNode sensorNode = node.Tag as SensorNode;
462 if (sensorNode != null) {
463 if (sensorNode.Plot) {
464 colors.Add(sensorNode.Sensor,
465 plotColorPalette[colorIndex % plotColorPalette.Length]);
466 selected.Add(sensorNode.Sensor);
471 sensorPlotColors = colors;
472 plotPanel.SetSensors(selected, colors);
475 private void nodeTextBoxText_EditorShowing(object sender,
478 e.Cancel = !(treeView.CurrentNode != null &&
479 (treeView.CurrentNode.Tag is SensorNode ||
480 treeView.CurrentNode.Tag is HardwareNode));
483 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
484 NodeControlValueEventArgs e) {
485 SensorNode node = e.Node.Tag as SensorNode;
486 e.Value = (node != null) && plotMenuItem.Checked;
489 private void exitClick(object sender, EventArgs e) {
493 private void timer_Tick(object sender, EventArgs e) {
494 computer.Accept(updateVisitor);
495 treeView.Invalidate();
496 plotPanel.InvalidatePlot();
501 if (wmiProvider != null)
502 wmiProvider.Update();
505 private void SaveConfiguration() {
506 plotPanel.SetCurrentSettings();
507 foreach (TreeColumn column in treeView.Columns)
508 settings.SetValue("treeView.Columns." + column.Header + ".Width",
511 this.settings.SetValue("listenerPort", server.ListenerPort);
513 string fileName = Path.ChangeExtension(
514 System.Windows.Forms.Application.ExecutablePath, ".config");
516 settings.Save(fileName);
517 } catch (UnauthorizedAccessException) {
518 MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
519 "The current settings could not be saved.",
520 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
521 } catch (IOException) {
522 MessageBox.Show("The path '" + fileName + "' is not writeable. " +
523 "The current settings could not be saved.",
524 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
528 private void MainForm_Load(object sender, EventArgs e) {
529 Rectangle newBounds = new Rectangle {
530 X = settings.GetValue("mainForm.Location.X", Location.X),
531 Y = settings.GetValue("mainForm.Location.Y", Location.Y),
532 Width = settings.GetValue("mainForm.Width", 470),
533 Height = settings.GetValue("mainForm.Height", 640)
536 Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
537 int.MinValue, int.MinValue);
539 foreach (Screen screen in Screen.AllScreens)
540 fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
542 Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
543 if (intersection.Width < 20 || intersection.Height < 20 ||
544 !settings.Contains("mainForm.Location.X")
546 newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
549 newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
550 (newBounds.Height / 2);
553 this.Bounds = newBounds;
556 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
558 systemTray.IsMainIconEnabled = false;
559 timer.Enabled = false;
562 if (runWebServer.Value)
564 systemTray.Dispose();
567 private void aboutMenuItem_Click(object sender, EventArgs e) {
568 new AboutBox().ShowDialog();
571 private void treeView_Click(object sender, EventArgs e) {
573 MouseEventArgs m = e as MouseEventArgs;
574 if (m == null || m.Button != MouseButtons.Right)
577 NodeControlInfo info = treeView.GetNodeControlInfoAt(
580 treeView.SelectedNode = info.Node;
581 if (info.Node != null) {
582 SensorNode node = info.Node.Tag as SensorNode;
583 if (node != null && node.Sensor != null) {
584 treeContextMenu.MenuItems.Clear();
585 if (node.Sensor.Parameters.Length > 0) {
586 MenuItem item = new MenuItem("Parameters...");
587 item.Click += delegate(object obj, EventArgs args) {
588 ShowParameterForm(node.Sensor);
590 treeContextMenu.MenuItems.Add(item);
592 if (nodeTextBoxText.EditEnabled) {
593 MenuItem item = new MenuItem("Rename");
594 item.Click += delegate(object obj, EventArgs args) {
595 nodeTextBoxText.BeginEdit();
597 treeContextMenu.MenuItems.Add(item);
599 if (node.IsVisible) {
600 MenuItem item = new MenuItem("Hide");
601 item.Click += delegate(object obj, EventArgs args) {
602 node.IsVisible = false;
604 treeContextMenu.MenuItems.Add(item);
606 MenuItem item = new MenuItem("Unhide");
607 item.Click += delegate(object obj, EventArgs args) {
608 node.IsVisible = true;
610 treeContextMenu.MenuItems.Add(item);
612 treeContextMenu.MenuItems.Add(new MenuItem("-"));
614 MenuItem item = new MenuItem("Show in Tray");
615 item.Checked = systemTray.Contains(node.Sensor);
616 item.Click += delegate(object obj, EventArgs args) {
618 systemTray.Remove(node.Sensor);
620 systemTray.Add(node.Sensor, true);
622 treeContextMenu.MenuItems.Add(item);
624 if (gadget != null) {
625 MenuItem item = new MenuItem("Show in Gadget");
626 item.Checked = gadget.Contains(node.Sensor);
627 item.Click += delegate(object obj, EventArgs args) {
629 gadget.Remove(node.Sensor);
631 gadget.Add(node.Sensor);
634 treeContextMenu.MenuItems.Add(item);
636 if (node.Sensor.Control != null) {
637 treeContextMenu.MenuItems.Add(new MenuItem("-"));
638 IControl control = node.Sensor.Control;
639 MenuItem controlItem = new MenuItem("Control");
640 MenuItem defaultItem = new MenuItem("Default");
641 defaultItem.Checked = control.ControlMode == ControlMode.Default;
642 controlItem.MenuItems.Add(defaultItem);
643 defaultItem.Click += delegate(object obj, EventArgs args) {
644 control.SetDefault();
646 MenuItem manualItem = new MenuItem("Manual");
647 controlItem.MenuItems.Add(manualItem);
648 manualItem.Checked = control.ControlMode == ControlMode.Software;
649 for (int i = 0; i <= 100; i += 5) {
650 if (i <= control.MaxSoftwareValue &&
651 i >= control.MinSoftwareValue) {
652 MenuItem item = new MenuItem(i + " %");
653 item.RadioCheck = true;
654 manualItem.MenuItems.Add(item);
655 item.Checked = control.ControlMode == ControlMode.Software &&
656 Math.Round(control.SoftwareValue) == i;
657 int softwareValue = i;
658 item.Click += delegate(object obj, EventArgs args) {
659 control.SetSoftware(softwareValue);
663 treeContextMenu.MenuItems.Add(controlItem);
666 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
669 HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
670 if (hardwareNode != null && hardwareNode.Hardware != null) {
671 treeContextMenu.MenuItems.Clear();
673 if (nodeTextBoxText.EditEnabled) {
674 MenuItem item = new MenuItem("Rename");
675 item.Click += delegate(object obj, EventArgs args) {
676 nodeTextBoxText.BeginEdit();
678 treeContextMenu.MenuItems.Add(item);
681 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
686 private void saveReportMenuItem_Click(object sender, EventArgs e) {
687 string report = computer.GetReport();
688 if (saveFileDialog.ShowDialog() == DialogResult.OK) {
689 using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
695 private void SysTrayHideShow() {
701 protected override void WndProc(ref Message m) {
702 const int WM_SYSCOMMAND = 0x112;
703 const int SC_MINIMIZE = 0xF020;
704 const int SC_CLOSE = 0xF060;
706 if (minimizeToTray.Value &&
707 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE) {
709 } else if (minimizeOnClose.Value &&
710 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE) {
712 * Apparently the user wants to minimize rather than close
713 * Now we still need to check if we're going to the tray or not
715 * Note: the correct way to do this would be to send out SC_MINIMIZE,
716 * but since the code here is so simple,
717 * that would just be a waste of time.
719 if (minimizeToTray.Value)
722 WindowState = FormWindowState.Minimized;
728 private void hideShowClick(object sender, EventArgs e) {
732 private void ShowParameterForm(ISensor sensor) {
733 ParameterForm form = new ParameterForm();
734 form.Parameters = sensor.Parameters;
735 form.captionLabel.Text = sensor.Name;
739 private void treeView_NodeMouseDoubleClick(object sender,
740 TreeNodeAdvMouseEventArgs e) {
741 SensorNode node = e.Node.Tag as SensorNode;
742 if (node != null && node.Sensor != null &&
743 node.Sensor.Parameters.Length > 0) {
744 ShowParameterForm(node.Sensor);
748 private void celsiusMenuItem_Click(object sender, EventArgs e) {
749 celsiusMenuItem.Checked = true;
750 fahrenheitMenuItem.Checked = false;
751 unitManager.TemperatureUnit = TemperatureUnit.Celsius;
754 private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
755 celsiusMenuItem.Checked = false;
756 fahrenheitMenuItem.Checked = true;
757 unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
760 private void sumbitReportMenuItem_Click(object sender, EventArgs e)
762 ReportForm form = new ReportForm();
763 form.Report = computer.GetReport();
767 private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
768 computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
774 private void MainForm_MoveOrResize(object sender, EventArgs e) {
775 if (WindowState != FormWindowState.Minimized) {
776 settings.SetValue("mainForm.Location.X", Bounds.X);
777 settings.SetValue("mainForm.Location.Y", Bounds.Y);
778 settings.SetValue("mainForm.Width", Bounds.Width);
779 settings.SetValue("mainForm.Height", Bounds.Height);
783 private void resetClick(object sender, EventArgs e) {
784 // disable the fallback MainIcon during reset, otherwise icon visibility
786 systemTray.IsMainIconEnabled = false;
789 // restore the MainIcon setting
790 systemTray.IsMainIconEnabled = minimizeToTray.Value;
793 private void treeView_MouseMove(object sender, MouseEventArgs e) {
794 selectionDragging = selectionDragging &
795 (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0;
797 if (selectionDragging)
798 treeView.SelectedNode = treeView.GetNodeAt(e.Location);
801 private void treeView_MouseDown(object sender, MouseEventArgs e) {
802 selectionDragging = true;
805 private void treeView_MouseUp(object sender, MouseEventArgs e) {
806 selectionDragging = false;
809 private void serverPortMenuItem_Click(object sender, EventArgs e) {
810 new PortForm(this).ShowDialog();
813 public HttpServer Server {
814 get { return server; }