Added additional Fintek chips to the lm-sensors interface.
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 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);
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 sensorNode.Sensor.SensorType == SensorType.Temperature) {
464 if (sensorNode.Plot) {
465 colors.Add(sensorNode.Sensor,
466 plotColorPalette[colorIndex % plotColorPalette.Length]);
467 selected.Add(sensorNode.Sensor);
472 sensorPlotColors = colors;
473 plotPanel.SetSensors(selected, colors);
476 private void nodeTextBoxText_EditorShowing(object sender,
479 e.Cancel = !(treeView.CurrentNode != null &&
480 (treeView.CurrentNode.Tag is SensorNode ||
481 treeView.CurrentNode.Tag is HardwareNode));
484 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
485 NodeControlValueEventArgs e) {
486 SensorNode node = e.Node.Tag as SensorNode;
487 e.Value = (node != null) &&
488 (node.Sensor.SensorType == SensorType.Temperature) &&
489 plotMenuItem.Checked;
492 private void exitClick(object sender, EventArgs e) {
496 private void timer_Tick(object sender, EventArgs e) {
497 computer.Accept(updateVisitor);
498 treeView.Invalidate();
499 plotPanel.Invalidate();
504 if (wmiProvider != null)
505 wmiProvider.Update();
508 private void SaveConfiguration() {
509 foreach (TreeColumn column in treeView.Columns)
510 settings.SetValue("treeView.Columns." + column.Header + ".Width",
513 this.settings.SetValue("listenerPort", server.ListenerPort);
515 string fileName = Path.ChangeExtension(
516 System.Windows.Forms.Application.ExecutablePath, ".config");
518 settings.Save(fileName);
519 } catch (UnauthorizedAccessException) {
520 MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
521 "The current settings could not be saved.",
522 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
523 } catch (IOException) {
524 MessageBox.Show("The path '" + fileName + "' is not writeable. " +
525 "The current settings could not be saved.",
526 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
530 private void MainForm_Load(object sender, EventArgs e) {
531 Rectangle newBounds = new Rectangle {
532 X = settings.GetValue("mainForm.Location.X", Location.X),
533 Y = settings.GetValue("mainForm.Location.Y", Location.Y),
534 Width = settings.GetValue("mainForm.Width", 470),
535 Height = settings.GetValue("mainForm.Height", 640)
538 Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
539 int.MinValue, int.MinValue);
541 foreach (Screen screen in Screen.AllScreens)
542 fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
544 Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
545 if (intersection.Width < 20 || intersection.Height < 20 ||
546 !settings.Contains("mainForm.Location.X")
548 newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
551 newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
552 (newBounds.Height / 2);
555 this.Bounds = newBounds;
558 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
560 systemTray.IsMainIconEnabled = false;
561 timer.Enabled = false;
564 if (runWebServer.Value)
566 systemTray.Dispose();
569 private void aboutMenuItem_Click(object sender, EventArgs e) {
570 new AboutBox().ShowDialog();
573 private void treeView_Click(object sender, EventArgs e) {
575 MouseEventArgs m = e as MouseEventArgs;
576 if (m == null || m.Button != MouseButtons.Right)
579 NodeControlInfo info = treeView.GetNodeControlInfoAt(
582 treeView.SelectedNode = info.Node;
583 if (info.Node != null) {
584 SensorNode node = info.Node.Tag as SensorNode;
585 if (node != null && node.Sensor != null) {
586 treeContextMenu.MenuItems.Clear();
587 if (node.Sensor.Parameters.Length > 0) {
588 MenuItem item = new MenuItem("Parameters...");
589 item.Click += delegate(object obj, EventArgs args) {
590 ShowParameterForm(node.Sensor);
592 treeContextMenu.MenuItems.Add(item);
594 if (nodeTextBoxText.EditEnabled) {
595 MenuItem item = new MenuItem("Rename");
596 item.Click += delegate(object obj, EventArgs args) {
597 nodeTextBoxText.BeginEdit();
599 treeContextMenu.MenuItems.Add(item);
601 if (node.IsVisible) {
602 MenuItem item = new MenuItem("Hide");
603 item.Click += delegate(object obj, EventArgs args) {
604 node.IsVisible = false;
606 treeContextMenu.MenuItems.Add(item);
608 MenuItem item = new MenuItem("Unhide");
609 item.Click += delegate(object obj, EventArgs args) {
610 node.IsVisible = true;
612 treeContextMenu.MenuItems.Add(item);
614 treeContextMenu.MenuItems.Add(new MenuItem("-"));
616 MenuItem item = new MenuItem("Show in Tray");
617 item.Checked = systemTray.Contains(node.Sensor);
618 item.Click += delegate(object obj, EventArgs args) {
620 systemTray.Remove(node.Sensor);
622 systemTray.Add(node.Sensor, true);
624 treeContextMenu.MenuItems.Add(item);
626 if (gadget != null) {
627 MenuItem item = new MenuItem("Show in Gadget");
628 item.Checked = gadget.Contains(node.Sensor);
629 item.Click += delegate(object obj, EventArgs args) {
631 gadget.Remove(node.Sensor);
633 gadget.Add(node.Sensor);
636 treeContextMenu.MenuItems.Add(item);
638 if (node.Sensor.Control != null) {
639 treeContextMenu.MenuItems.Add(new MenuItem("-"));
640 IControl control = node.Sensor.Control;
641 MenuItem controlItem = new MenuItem("Control");
642 MenuItem defaultItem = new MenuItem("Default");
643 defaultItem.Checked = control.ControlMode == ControlMode.Default;
644 controlItem.MenuItems.Add(defaultItem);
645 defaultItem.Click += delegate(object obj, EventArgs args) {
646 control.SetDefault();
648 MenuItem manualItem = new MenuItem("Manual");
649 controlItem.MenuItems.Add(manualItem);
650 manualItem.Checked = control.ControlMode == ControlMode.Software;
651 for (int i = 0; i <= 100; i += 5) {
652 if (i <= control.MaxSoftwareValue &&
653 i >= control.MinSoftwareValue) {
654 MenuItem item = new MenuItem(i + " %");
655 item.RadioCheck = true;
656 manualItem.MenuItems.Add(item);
657 item.Checked = control.ControlMode == ControlMode.Software &&
658 Math.Round(control.SoftwareValue) == i;
659 int softwareValue = i;
660 item.Click += delegate(object obj, EventArgs args) {
661 control.SetSoftware(softwareValue);
665 treeContextMenu.MenuItems.Add(controlItem);
668 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
671 HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
672 if (hardwareNode != null && hardwareNode.Hardware != null) {
673 treeContextMenu.MenuItems.Clear();
675 if (nodeTextBoxText.EditEnabled) {
676 MenuItem item = new MenuItem("Rename");
677 item.Click += delegate(object obj, EventArgs args) {
678 nodeTextBoxText.BeginEdit();
680 treeContextMenu.MenuItems.Add(item);
683 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
688 private void saveReportMenuItem_Click(object sender, EventArgs e) {
689 string report = computer.GetReport();
690 if (saveFileDialog.ShowDialog() == DialogResult.OK) {
691 using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
697 private void SysTrayHideShow() {
703 protected override void WndProc(ref Message m) {
704 const int WM_SYSCOMMAND = 0x112;
705 const int SC_MINIMIZE = 0xF020;
706 const int SC_CLOSE = 0xF060;
708 if (minimizeToTray.Value &&
709 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE) {
711 } else if (minimizeOnClose.Value &&
712 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE) {
714 * Apparently the user wants to minimize rather than close
715 * Now we still need to check if we're going to the tray or not
717 * Note: the correct way to do this would be to send out SC_MINIMIZE,
718 * but since the code here is so simple,
719 * that would just be a waste of time.
721 if (minimizeToTray.Value)
724 WindowState = FormWindowState.Minimized;
730 private void hideShowClick(object sender, EventArgs e) {
734 private void ShowParameterForm(ISensor sensor) {
735 ParameterForm form = new ParameterForm();
736 form.Parameters = sensor.Parameters;
737 form.captionLabel.Text = sensor.Name;
741 private void treeView_NodeMouseDoubleClick(object sender,
742 TreeNodeAdvMouseEventArgs e) {
743 SensorNode node = e.Node.Tag as SensorNode;
744 if (node != null && node.Sensor != null &&
745 node.Sensor.Parameters.Length > 0) {
746 ShowParameterForm(node.Sensor);
750 private void celsiusMenuItem_Click(object sender, EventArgs e) {
751 celsiusMenuItem.Checked = true;
752 fahrenheitMenuItem.Checked = false;
753 unitManager.TemperatureUnit = TemperatureUnit.Celsius;
756 private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
757 celsiusMenuItem.Checked = false;
758 fahrenheitMenuItem.Checked = true;
759 unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
762 private void sumbitReportMenuItem_Click(object sender, EventArgs e)
764 ReportForm form = new ReportForm();
765 form.Report = computer.GetReport();
769 private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
770 computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
776 private void MainForm_MoveOrResize(object sender, EventArgs e) {
777 if (WindowState != FormWindowState.Minimized) {
778 settings.SetValue("mainForm.Location.X", Bounds.X);
779 settings.SetValue("mainForm.Location.Y", Bounds.Y);
780 settings.SetValue("mainForm.Width", Bounds.Width);
781 settings.SetValue("mainForm.Height", Bounds.Height);
785 private void resetClick(object sender, EventArgs e) {
786 // disable the fallback MainIcon during reset, otherwise icon visibility
788 systemTray.IsMainIconEnabled = false;
791 // restore the MainIcon setting
792 systemTray.IsMainIconEnabled = minimizeToTray.Value;
795 private void treeView_MouseMove(object sender, MouseEventArgs e) {
796 selectionDragging = selectionDragging &
797 (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0;
799 if (selectionDragging)
800 treeView.SelectedNode = treeView.GetNodeAt(e.Location);
803 private void treeView_MouseDown(object sender, MouseEventArgs e) {
804 selectionDragging = true;
807 private void treeView_MouseUp(object sender, MouseEventArgs e) {
808 selectionDragging = false;
811 private void serverPortMenuItem_Click(object sender, EventArgs e) {
812 new PortForm(this).ShowDialog();
815 public HttpServer Server {
816 get { return server; }