Improved the data compression for storing the recorded sensor values in the config file.
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-2012 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 readGpuSensors;
58 private UserOption readFanControllersSensors;
59 private UserOption readHddSensors;
61 private UserOption showGadget;
62 private UserRadioGroup plotLocation;
63 private WmiProvider wmiProvider;
65 private UserOption runWebServer;
66 private HttpServer server;
68 private bool selectionDragging = false;
71 InitializeComponent();
73 // check if the OpenHardwareMonitorLib assembly has the correct version
74 if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
75 Assembly.GetExecutingAssembly().GetName().Version) {
77 "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
78 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
82 this.settings = new PersistentSettings();
83 this.settings.Load(Path.ChangeExtension(
84 Application.ExecutablePath, ".config"));
86 this.unitManager = new UnitManager(settings);
88 // make sure the buffers used for double buffering are not disposed
89 // after each draw call
90 BufferedGraphicsManager.Current.MaximumBuffer =
91 Screen.PrimaryScreen.Bounds.Size;
93 // set the DockStyle here, to avoid conflicts with the MainMenu
94 this.splitContainer.Dock = DockStyle.Fill;
96 this.Font = SystemFonts.MessageBoxFont;
97 treeView.Font = SystemFonts.MessageBoxFont;
99 plotPanel = new PlotPanel(settings);
100 plotPanel.Font = SystemFonts.MessageBoxFont;
101 plotPanel.Dock = DockStyle.Fill;
103 nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
104 nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
105 nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
106 nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
107 nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
108 nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
110 foreach (TreeColumn column in treeView.Columns)
111 column.Width = Math.Max(20, Math.Min(400,
112 settings.GetValue("treeView.Columns." + column.Header + ".Width",
115 treeModel = new TreeModel();
116 root = new Node(System.Environment.MachineName);
117 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
119 treeModel.Nodes.Add(root);
120 treeView.Model = treeModel;
122 this.computer = new Computer(settings);
124 systemTray = new SystemTray(computer, settings, unitManager);
125 systemTray.HideShowCommand += hideShowClick;
126 systemTray.ExitCommand += exitClick;
128 int p = (int)Environment.OSVersion.Platform;
129 if ((p == 4) || (p == 128)) { // Unix
130 treeView.RowHeight = Math.Max(treeView.RowHeight, 18);
131 splitContainer.BorderStyle = BorderStyle.None;
132 splitContainer.Border3DStyle = Border3DStyle.Adjust;
133 splitContainer.SplitterWidth = 4;
134 treeView.BorderStyle = BorderStyle.Fixed3D;
135 plotPanel.BorderStyle = BorderStyle.Fixed3D;
136 gadgetMenuItem.Visible = false;
137 minCloseMenuItem.Visible = false;
138 minTrayMenuItem.Visible = false;
139 startMinMenuItem.Visible = false;
141 treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);
143 gadget = new SensorGadget(computer, settings, unitManager);
144 gadget.HideShowCommand += hideShowClick;
146 wmiProvider = new WmiProvider(computer);
149 plotColorPalette = new Color[13];
150 plotColorPalette[0] = Color.Blue;
151 plotColorPalette[1] = Color.OrangeRed;
152 plotColorPalette[2] = Color.Green;
153 plotColorPalette[3] = Color.LightSeaGreen;
154 plotColorPalette[4] = Color.Goldenrod;
155 plotColorPalette[5] = Color.DarkViolet;
156 plotColorPalette[6] = Color.YellowGreen;
157 plotColorPalette[7] = Color.SaddleBrown;
158 plotColorPalette[8] = Color.RoyalBlue;
159 plotColorPalette[9] = Color.DeepPink;
160 plotColorPalette[10] = Color.MediumSeaGreen;
161 plotColorPalette[11] = Color.Olive;
162 plotColorPalette[12] = Color.Firebrick;
164 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
165 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
169 timer.Enabled = true;
171 showHiddenSensors = new UserOption("hiddenMenuItem", false,
172 hiddenMenuItem, settings);
173 showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
174 treeModel.ForceVisible = showHiddenSensors.Value;
177 showValue = new UserOption("valueMenuItem", true, valueMenuItem,
179 showValue.Changed += delegate(object sender, EventArgs e) {
180 treeView.Columns[1].IsVisible = showValue.Value;
183 showMin = new UserOption("minMenuItem", false, minMenuItem, settings);
184 showMin.Changed += delegate(object sender, EventArgs e) {
185 treeView.Columns[2].IsVisible = showMin.Value;
188 showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings);
189 showMax.Changed += delegate(object sender, EventArgs e) {
190 treeView.Columns[3].IsVisible = showMax.Value;
193 startMinimized = new UserOption("startMinMenuItem", false,
194 startMinMenuItem, settings);
196 minimizeToTray = new UserOption("minTrayMenuItem", true,
197 minTrayMenuItem, settings);
198 minimizeToTray.Changed += delegate(object sender, EventArgs e) {
199 systemTray.IsMainIconEnabled = minimizeToTray.Value;
202 minimizeOnClose = new UserOption("minCloseMenuItem", false,
203 minCloseMenuItem, settings);
205 autoStart = new UserOption(null, startupManager.Startup,
206 startupMenuItem, settings);
207 autoStart.Changed += delegate(object sender, EventArgs e) {
209 startupManager.Startup = autoStart.Value;
210 } catch (InvalidOperationException) {
211 MessageBox.Show("Updating the auto-startup option failed.", "Error",
212 MessageBoxButtons.OK, MessageBoxIcon.Error);
213 autoStart.Value = startupManager.Startup;
217 readMainboardSensors = new UserOption("mainboardMenuItem", true,
218 mainboardMenuItem, settings);
219 readMainboardSensors.Changed += delegate(object sender, EventArgs e) {
220 computer.MainboardEnabled = readMainboardSensors.Value;
223 readCpuSensors = new UserOption("cpuMenuItem", true,
224 cpuMenuItem, settings);
225 readCpuSensors.Changed += delegate(object sender, EventArgs e) {
226 computer.CPUEnabled = readCpuSensors.Value;
229 readGpuSensors = new UserOption("gpuMenuItem", true,
230 gpuMenuItem, settings);
231 readGpuSensors.Changed += delegate(object sender, EventArgs e) {
232 computer.GPUEnabled = readGpuSensors.Value;
235 readFanControllersSensors = new UserOption("fanControllerMenuItem", true,
236 fanControllerMenuItem, settings);
237 readFanControllersSensors.Changed += delegate(object sender, EventArgs e) {
238 computer.FanControllerEnabled = readFanControllersSensors.Value;
241 readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
243 readHddSensors.Changed += delegate(object sender, EventArgs e) {
244 computer.HDDEnabled = readHddSensors.Value;
247 showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
249 showGadget.Changed += delegate(object sender, EventArgs e) {
251 gadget.Visible = showGadget.Value;
254 celsiusMenuItem.Checked =
255 unitManager.TemperatureUnit == TemperatureUnit.Celsius;
256 fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;
258 server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085));
259 runWebServer = new UserOption("runWebServerMenuItem", false,
260 runWebServerMenuItem, settings);
261 runWebServer.Changed += delegate(object sender, EventArgs e) {
262 if (runWebServer.Value)
263 runWebServer.Value = server.startHTTPListener();
265 server.stopHTTPListener();
268 InitializePlotForm();
270 startupMenuItem.Visible = startupManager.IsAvailable;
272 if (startMinMenuItem.Checked) {
273 if (!minTrayMenuItem.Checked) {
274 WindowState = FormWindowState.Minimized;
281 // Create a handle, otherwise calling Close() does not fire FormClosed
282 IntPtr handle = Handle;
284 // Make sure the settings are saved when the user logs off
285 Microsoft.Win32.SystemEvents.SessionEnded += delegate {
287 if (runWebServer.Value)
293 private void InitializePlotForm() {
294 plotForm = new Form();
295 plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
296 plotForm.ShowInTaskbar = false;
297 plotForm.StartPosition = FormStartPosition.Manual;
298 this.AddOwnedForm(plotForm);
299 plotForm.Bounds = new Rectangle {
300 X = settings.GetValue("plotForm.Location.X", -100000),
301 Y = settings.GetValue("plotForm.Location.Y", 100),
302 Width = settings.GetValue("plotForm.Width", 600),
303 Height = settings.GetValue("plotForm.Height", 400)
306 showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
307 plotLocation = new UserRadioGroup("plotLocation", 0,
308 new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
311 showPlot.Changed += delegate(object sender, EventArgs e) {
312 if (plotLocation.Value == 0) {
313 if (showPlot.Value && this.Visible)
318 splitContainer.Panel2Collapsed = !showPlot.Value;
320 treeView.Invalidate();
322 plotLocation.Changed += delegate(object sender, EventArgs e) {
323 switch (plotLocation.Value) {
325 splitContainer.Panel2.Controls.Clear();
326 splitContainer.Panel2Collapsed = true;
327 plotForm.Controls.Add(plotPanel);
328 if (showPlot.Value && this.Visible)
332 plotForm.Controls.Clear();
334 splitContainer.Orientation = Orientation.Horizontal;
335 splitContainer.Panel2.Controls.Add(plotPanel);
336 splitContainer.Panel2Collapsed = !showPlot.Value;
339 plotForm.Controls.Clear();
341 splitContainer.Orientation = Orientation.Vertical;
342 splitContainer.Panel2.Controls.Add(plotPanel);
343 splitContainer.Panel2Collapsed = !showPlot.Value;
348 plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) {
349 if (e.CloseReason == CloseReason.UserClosing) {
350 // just switch off the plotting when the user closes the form
351 if (plotLocation.Value == 0) {
352 showPlot.Value = false;
358 EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
359 if (plotForm.WindowState != FormWindowState.Minimized) {
360 settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
361 settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
362 settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
363 settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
366 plotForm.Move += moveOrResizePlotForm;
367 plotForm.Resize += moveOrResizePlotForm;
369 plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
370 Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
371 Screen screen = Screen.FromRectangle(bounds);
372 Rectangle intersection =
373 Rectangle.Intersect(screen.WorkingArea, bounds);
374 if (intersection.Width < Math.Min(16, bounds.Width) ||
375 intersection.Height < Math.Min(16, bounds.Height)) {
376 plotForm.Location = new Point(
377 screen.WorkingArea.Width / 2 - bounds.Width / 2,
378 screen.WorkingArea.Height / 2 - bounds.Height / 2);
382 this.VisibleChanged += delegate(object sender, EventArgs e) {
383 if (this.Visible && showPlot.Value && plotLocation.Value == 0)
390 private void InsertSorted(Collection<Node> nodes, HardwareNode node) {
392 while (i < nodes.Count && nodes[i] is HardwareNode &&
393 ((HardwareNode)nodes[i]).Hardware.HardwareType <
394 node.Hardware.HardwareType)
396 nodes.Insert(i, node);
399 private void SubHardwareAdded(IHardware hardware, Node node) {
400 HardwareNode hardwareNode =
401 new HardwareNode(hardware, settings, unitManager);
402 hardwareNode.PlotSelectionChanged += PlotSelectionChanged;
404 InsertSorted(node.Nodes, hardwareNode);
406 foreach (IHardware subHardware in hardware.SubHardware)
407 SubHardwareAdded(subHardware, hardwareNode);
410 private void HardwareAdded(IHardware hardware) {
411 SubHardwareAdded(hardware, root);
412 PlotSelectionChanged(this, null);
415 private void HardwareRemoved(IHardware hardware) {
416 List<HardwareNode> nodesToRemove = new List<HardwareNode>();
417 foreach (Node node in root.Nodes) {
418 HardwareNode hardwareNode = node as HardwareNode;
419 if (hardwareNode != null && hardwareNode.Hardware == hardware)
420 nodesToRemove.Add(hardwareNode);
422 foreach (HardwareNode hardwareNode in nodesToRemove) {
423 root.Nodes.Remove(hardwareNode);
424 hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
426 PlotSelectionChanged(this, null);
429 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
430 Node node = e.Node.Tag as Node;
433 if (node.IsVisible) {
434 SensorNode sensorNode = node as SensorNode;
435 if (plotMenuItem.Checked && sensorNode != null &&
436 sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
439 e.TextColor = Color.DarkGray;
444 private void PlotSelectionChanged(object sender, EventArgs e) {
445 List<ISensor> selected = new List<ISensor>();
446 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
448 foreach (TreeNodeAdv node in treeView.AllNodes) {
449 SensorNode sensorNode = node.Tag as SensorNode;
450 if (sensorNode != null &&
451 sensorNode.Sensor.SensorType == SensorType.Temperature) {
452 if (sensorNode.Plot) {
453 colors.Add(sensorNode.Sensor,
454 plotColorPalette[colorIndex % plotColorPalette.Length]);
455 selected.Add(sensorNode.Sensor);
460 sensorPlotColors = colors;
461 plotPanel.SetSensors(selected, colors);
464 private void nodeTextBoxText_EditorShowing(object sender,
467 e.Cancel = !(treeView.CurrentNode != null &&
468 (treeView.CurrentNode.Tag is SensorNode ||
469 treeView.CurrentNode.Tag is HardwareNode));
472 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
473 NodeControlValueEventArgs e) {
474 SensorNode node = e.Node.Tag as SensorNode;
475 e.Value = (node != null) &&
476 (node.Sensor.SensorType == SensorType.Temperature) &&
477 plotMenuItem.Checked;
480 private void exitClick(object sender, EventArgs e) {
484 private void timer_Tick(object sender, EventArgs e) {
485 computer.Accept(updateVisitor);
486 treeView.Invalidate();
487 plotPanel.Invalidate();
492 if (wmiProvider != null)
493 wmiProvider.Update();
496 private void SaveConfiguration() {
497 foreach (TreeColumn column in treeView.Columns)
498 settings.SetValue("treeView.Columns." + column.Header + ".Width",
501 this.settings.SetValue("listenerPort", server.ListenerPort);
503 string fileName = Path.ChangeExtension(
504 System.Windows.Forms.Application.ExecutablePath, ".config");
506 settings.Save(fileName);
507 } catch (UnauthorizedAccessException) {
508 MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
509 "The current settings could not be saved.",
510 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
511 } catch (IOException) {
512 MessageBox.Show("The path '" + fileName + "' is not writeable. " +
513 "The current settings could not be saved.",
514 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
518 private void MainForm_Load(object sender, EventArgs e) {
519 Rectangle newBounds = new Rectangle {
520 X = settings.GetValue("mainForm.Location.X", Location.X),
521 Y = settings.GetValue("mainForm.Location.Y", Location.Y),
522 Width = settings.GetValue("mainForm.Width", 470),
523 Height = settings.GetValue("mainForm.Height", 640)
526 Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
527 int.MinValue, int.MinValue);
529 foreach (Screen screen in Screen.AllScreens)
530 fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
532 Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
533 if (intersection.Width < 20 || intersection.Height < 20 ||
534 !settings.Contains("mainForm.Location.X")
536 newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
539 newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
540 (newBounds.Height / 2);
543 this.Bounds = newBounds;
546 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
548 systemTray.IsMainIconEnabled = false;
549 timer.Enabled = false;
552 if (runWebServer.Value)
554 systemTray.Dispose();
557 private void aboutMenuItem_Click(object sender, EventArgs e) {
558 new AboutBox().ShowDialog();
561 private void treeView_Click(object sender, EventArgs e) {
563 MouseEventArgs m = e as MouseEventArgs;
564 if (m == null || m.Button != MouseButtons.Right)
567 NodeControlInfo info = treeView.GetNodeControlInfoAt(
570 treeView.SelectedNode = info.Node;
571 if (info.Node != null) {
572 SensorNode node = info.Node.Tag as SensorNode;
573 if (node != null && node.Sensor != null) {
574 treeContextMenu.MenuItems.Clear();
575 if (node.Sensor.Parameters.Length > 0) {
576 MenuItem item = new MenuItem("Parameters...");
577 item.Click += delegate(object obj, EventArgs args) {
578 ShowParameterForm(node.Sensor);
580 treeContextMenu.MenuItems.Add(item);
582 if (nodeTextBoxText.EditEnabled) {
583 MenuItem item = new MenuItem("Rename");
584 item.Click += delegate(object obj, EventArgs args) {
585 nodeTextBoxText.BeginEdit();
587 treeContextMenu.MenuItems.Add(item);
589 if (node.IsVisible) {
590 MenuItem item = new MenuItem("Hide");
591 item.Click += delegate(object obj, EventArgs args) {
592 node.IsVisible = false;
594 treeContextMenu.MenuItems.Add(item);
596 MenuItem item = new MenuItem("Unhide");
597 item.Click += delegate(object obj, EventArgs args) {
598 node.IsVisible = true;
600 treeContextMenu.MenuItems.Add(item);
602 treeContextMenu.MenuItems.Add(new MenuItem("-"));
604 MenuItem item = new MenuItem("Show in Tray");
605 item.Checked = systemTray.Contains(node.Sensor);
606 item.Click += delegate(object obj, EventArgs args) {
608 systemTray.Remove(node.Sensor);
610 systemTray.Add(node.Sensor, true);
612 treeContextMenu.MenuItems.Add(item);
614 if (gadget != null) {
615 MenuItem item = new MenuItem("Show in Gadget");
616 item.Checked = gadget.Contains(node.Sensor);
617 item.Click += delegate(object obj, EventArgs args) {
619 gadget.Remove(node.Sensor);
621 gadget.Add(node.Sensor);
624 treeContextMenu.MenuItems.Add(item);
626 if (node.Sensor.Control != null) {
627 treeContextMenu.MenuItems.Add(new MenuItem("-"));
628 IControl control = node.Sensor.Control;
629 MenuItem controlItem = new MenuItem("Control");
630 MenuItem defaultItem = new MenuItem("Default");
631 defaultItem.Checked = control.ControlMode == ControlMode.Default;
632 controlItem.MenuItems.Add(defaultItem);
633 defaultItem.Click += delegate(object obj, EventArgs args) {
634 control.SetDefault();
636 MenuItem manualItem = new MenuItem("Manual");
637 controlItem.MenuItems.Add(manualItem);
638 manualItem.Checked = control.ControlMode == ControlMode.Software;
639 for (int i = 0; i <= 100; i += 5) {
640 if (i <= control.MaxSoftwareValue &&
641 i >= control.MinSoftwareValue) {
642 MenuItem item = new MenuItem(i + " %");
643 manualItem.MenuItems.Add(item);
644 item.Checked = control.ControlMode == ControlMode.Software &&
645 Math.Round(control.SoftwareValue) == i;
646 int softwareValue = i;
647 item.Click += delegate(object obj, EventArgs args) {
648 control.SetSoftware(softwareValue);
652 treeContextMenu.MenuItems.Add(controlItem);
655 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
658 HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
659 if (hardwareNode != null && hardwareNode.Hardware != null) {
660 treeContextMenu.MenuItems.Clear();
662 if (nodeTextBoxText.EditEnabled) {
663 MenuItem item = new MenuItem("Rename");
664 item.Click += delegate(object obj, EventArgs args) {
665 nodeTextBoxText.BeginEdit();
667 treeContextMenu.MenuItems.Add(item);
670 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
675 private void saveReportMenuItem_Click(object sender, EventArgs e) {
676 string report = computer.GetReport();
677 if (saveFileDialog.ShowDialog() == DialogResult.OK) {
678 using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
684 private void SysTrayHideShow() {
690 protected override void WndProc(ref Message m) {
691 const int WM_SYSCOMMAND = 0x112;
692 const int SC_MINIMIZE = 0xF020;
693 const int SC_CLOSE = 0xF060;
695 if (minimizeToTray.Value &&
696 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE) {
698 } else if (minimizeOnClose.Value &&
699 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE) {
701 * Apparently the user wants to minimize rather than close
702 * Now we still need to check if we're going to the tray or not
704 * Note: the correct way to do this would be to send out SC_MINIMIZE,
705 * but since the code here is so simple,
706 * that would just be a waste of time.
708 if (minimizeToTray.Value)
711 WindowState = FormWindowState.Minimized;
717 private void hideShowClick(object sender, EventArgs e) {
721 private void ShowParameterForm(ISensor sensor) {
722 ParameterForm form = new ParameterForm();
723 form.Parameters = sensor.Parameters;
724 form.captionLabel.Text = sensor.Name;
728 private void treeView_NodeMouseDoubleClick(object sender,
729 TreeNodeAdvMouseEventArgs e) {
730 SensorNode node = e.Node.Tag as SensorNode;
731 if (node != null && node.Sensor != null &&
732 node.Sensor.Parameters.Length > 0) {
733 ShowParameterForm(node.Sensor);
737 private void celsiusMenuItem_Click(object sender, EventArgs e) {
738 celsiusMenuItem.Checked = true;
739 fahrenheitMenuItem.Checked = false;
740 unitManager.TemperatureUnit = TemperatureUnit.Celsius;
743 private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
744 celsiusMenuItem.Checked = false;
745 fahrenheitMenuItem.Checked = true;
746 unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
749 private void sumbitReportMenuItem_Click(object sender, EventArgs e)
751 ReportForm form = new ReportForm();
752 form.Report = computer.GetReport();
756 private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
757 computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
763 private void MainForm_MoveOrResize(object sender, EventArgs e) {
764 if (WindowState != FormWindowState.Minimized) {
765 settings.SetValue("mainForm.Location.X", Bounds.X);
766 settings.SetValue("mainForm.Location.Y", Bounds.Y);
767 settings.SetValue("mainForm.Width", Bounds.Width);
768 settings.SetValue("mainForm.Height", Bounds.Height);
772 private void resetClick(object sender, EventArgs e) {
773 // disable the fallback MainIcon during reset, otherwise icon visibility
775 systemTray.IsMainIconEnabled = false;
778 // restore the MainIcon setting
779 systemTray.IsMainIconEnabled = minimizeToTray.Value;
782 private void treeView_MouseMove(object sender, MouseEventArgs e) {
783 selectionDragging = selectionDragging &
784 (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0;
786 if (selectionDragging)
787 treeView.SelectedNode = treeView.GetNodeAt(e.Location);
790 private void treeView_MouseDown(object sender, MouseEventArgs e) {
791 selectionDragging = true;
794 private void treeView_MouseUp(object sender, MouseEventArgs e) {
795 selectionDragging = false;
798 private void serverPortMenuItem_Click(object sender, EventArgs e) {
799 new PortForm(this).ShowDialog();
802 public HttpServer Server {
803 get { return server; }