GUI/MainForm.cs
author StephaneLenclud
Mon, 02 Feb 2015 12:51:06 +0100
branchMiniDisplay
changeset 436 e9aefd454d1e
parent 435 9ffcd8ed8537
child 438 f590956d3234
permissions -rw-r--r--
At last we can output stuff on our display.
The whole thing is still quite broken though.
Rebase: No start-up but that's ok.
moel@1
     1
/*
moel@344
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@344
     6
 
moel@395
     7
  Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	Copyright (C) 2010 Paul Werelds <paul@werelds.net>
moel@348
     9
	Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
moel@1
    10
moel@1
    11
*/
moel@1
    12
moel@1
    13
using System;
moel@1
    14
using System.Collections.Generic;
moel@360
    15
using System.Collections.ObjectModel;
moel@1
    16
using System.ComponentModel;
moel@1
    17
using System.Drawing;
moel@83
    18
using System.IO;
moel@291
    19
using System.Reflection;
moel@1
    20
using System.Windows.Forms;
StephaneLenclud@434
    21
using System.Windows;
moel@1
    22
using Aga.Controls.Tree;
moel@1
    23
using Aga.Controls.Tree.NodeControls;
moel@1
    24
using OpenHardwareMonitor.Hardware;
paulwerelds@227
    25
using OpenHardwareMonitor.WMI;
moel@348
    26
using OpenHardwareMonitor.Utilities;
moel@1
    27
StephaneLenclud@435
    28
moel@1
    29
namespace OpenHardwareMonitor.GUI {
moel@1
    30
  public partial class MainForm : Form {
moel@1
    31
moel@165
    32
    private PersistentSettings settings;
moel@165
    33
    private UnitManager unitManager;
moel@165
    34
    private Computer computer;
moel@1
    35
    private Node root;
moel@1
    36
    private TreeModel treeModel;
moel@1
    37
    private IDictionary<ISensor, Color> sensorPlotColors = 
moel@1
    38
      new Dictionary<ISensor, Color>();
moel@1
    39
    private Color[] plotColorPalette;
StephaneLenclud@433
    40
    private SystemTray systemTray;
StephaneLenclud@433
    41
    private SoundGraphDisplay soundGraphDisplay;
StephaneLenclud@436
    42
    private bool displayTick;
moel@82
    43
    private StartupManager startupManager = new StartupManager();
moel@110
    44
    private UpdateVisitor updateVisitor = new UpdateVisitor();
moel@176
    45
    private SensorGadget gadget;
moel@295
    46
    private Form plotForm;
moel@326
    47
    private PlotPanel plotPanel;
moel@1
    48
moel@156
    49
    private UserOption showHiddenSensors;
moel@156
    50
    private UserOption showPlot;
moel@156
    51
    private UserOption showValue;
moel@156
    52
    private UserOption showMin;
moel@156
    53
    private UserOption showMax;
moel@156
    54
    private UserOption startMinimized;
moel@156
    55
    private UserOption minimizeToTray;
paulwerelds@198
    56
    private UserOption minimizeOnClose;
moel@156
    57
    private UserOption autoStart;
moel@360
    58
moel@360
    59
    private UserOption readMainboardSensors;
moel@360
    60
    private UserOption readCpuSensors;
moel@370
    61
    private UserOption readRamSensors;
moel@360
    62
    private UserOption readGpuSensors;
moel@360
    63
    private UserOption readFanControllersSensors;
moel@156
    64
    private UserOption readHddSensors;
moel@360
    65
moel@176
    66
    private UserOption showGadget;
moel@295
    67
    private UserRadioGroup plotLocation;
moel@348
    68
    private WmiProvider wmiProvider;
paulwerelds@223
    69
moel@348
    70
    private UserOption runWebServer;
moel@348
    71
    private HttpServer server;
moel@156
    72
moel@420
    73
    private UserOption logSensors;
moel@422
    74
    private UserRadioGroup loggingInterval;
moel@420
    75
    private Logger logger;
moel@420
    76
moel@288
    77
    private bool selectionDragging = false;
moel@288
    78
moel@28
    79
    public MainForm() {      
moel@1
    80
      InitializeComponent();
moel@156
    81
moel@291
    82
      // check if the OpenHardwareMonitorLib assembly has the correct version
moel@291
    83
      if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
moel@291
    84
        Assembly.GetExecutingAssembly().GetName().Version) {
moel@291
    85
        MessageBox.Show(
moel@291
    86
          "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
moel@291
    87
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@291
    88
        Environment.Exit(0);
moel@291
    89
      }
moel@291
    90
moel@165
    91
      this.settings = new PersistentSettings();      
moel@165
    92
      this.settings.Load(Path.ChangeExtension(
paulwerelds@198
    93
        Application.ExecutablePath, ".config"));
moel@165
    94
moel@165
    95
      this.unitManager = new UnitManager(settings);
moel@165
    96
moel@304
    97
      // make sure the buffers used for double buffering are not disposed 
moel@304
    98
      // after each draw call
moel@304
    99
      BufferedGraphicsManager.Current.MaximumBuffer =
moel@304
   100
        Screen.PrimaryScreen.Bounds.Size;  
moel@304
   101
moel@156
   102
      // set the DockStyle here, to avoid conflicts with the MainMenu
moel@156
   103
      this.splitContainer.Dock = DockStyle.Fill;
moel@202
   104
            
moel@1
   105
      this.Font = SystemFonts.MessageBoxFont;
moel@1
   106
      treeView.Font = SystemFonts.MessageBoxFont;
moel@326
   107
moel@400
   108
      plotPanel = new PlotPanel(settings, unitManager);
moel@326
   109
      plotPanel.Font = SystemFonts.MessageBoxFont;
moel@326
   110
      plotPanel.Dock = DockStyle.Fill;
moel@1
   111
      
moel@133
   112
      nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
moel@133
   113
      nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
moel@133
   114
      nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
moel@133
   115
      nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
moel@133
   116
      nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
moel@141
   117
      nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
moel@1
   118
moel@113
   119
      foreach (TreeColumn column in treeView.Columns) 
moel@165
   120
        column.Width = Math.Max(20, Math.Min(400,
moel@166
   121
          settings.GetValue("treeView.Columns." + column.Header + ".Width",
moel@113
   122
          column.Width)));
moel@113
   123
moel@1
   124
      treeModel = new TreeModel();
moel@1
   125
      root = new Node(System.Environment.MachineName);
moel@1
   126
      root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
moel@1
   127
      
moel@1
   128
      treeModel.Nodes.Add(root);
moel@165
   129
      treeView.Model = treeModel;
moel@40
   130
moel@165
   131
      this.computer = new Computer(settings);
moel@165
   132
moel@362
   133
      systemTray = new SystemTray(computer, settings, unitManager);
moel@133
   134
      systemTray.HideShowCommand += hideShowClick;
moel@133
   135
      systemTray.ExitCommand += exitClick;
StephaneLenclud@433
   136
  
StephaneLenclud@434
   137
      soundGraphDisplay = new SoundGraphDisplay(computer, settings, unitManager);
StephaneLenclud@434
   138
 
moel@1
   139
moel@202
   140
      int p = (int)Environment.OSVersion.Platform;
moel@202
   141
      if ((p == 4) || (p == 128)) { // Unix
moel@287
   142
        treeView.RowHeight = Math.Max(treeView.RowHeight, 18); 
moel@202
   143
        splitContainer.BorderStyle = BorderStyle.None;
moel@202
   144
        splitContainer.Border3DStyle = Border3DStyle.Adjust;
moel@202
   145
        splitContainer.SplitterWidth = 4;
moel@202
   146
        treeView.BorderStyle = BorderStyle.Fixed3D;
moel@202
   147
        plotPanel.BorderStyle = BorderStyle.Fixed3D;
moel@202
   148
        gadgetMenuItem.Visible = false;
moel@202
   149
        minCloseMenuItem.Visible = false;
moel@269
   150
        minTrayMenuItem.Visible = false;
moel@269
   151
        startMinMenuItem.Visible = false;
moel@202
   152
      } else { // Windows
moel@287
   153
        treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18); 
moel@267
   154
moel@202
   155
        gadget = new SensorGadget(computer, settings, unitManager);
moel@244
   156
        gadget.HideShowCommand += hideShowClick;
moel@244
   157
moel@232
   158
        wmiProvider = new WmiProvider(computer);
moel@327
   159
      }
moel@86
   160
moel@421
   161
      logger = new Logger(computer);
moel@421
   162
moel@111
   163
      plotColorPalette = new Color[13];
moel@1
   164
      plotColorPalette[0] = Color.Blue;
moel@1
   165
      plotColorPalette[1] = Color.OrangeRed;
moel@1
   166
      plotColorPalette[2] = Color.Green;
moel@1
   167
      plotColorPalette[3] = Color.LightSeaGreen;
moel@1
   168
      plotColorPalette[4] = Color.Goldenrod;
moel@1
   169
      plotColorPalette[5] = Color.DarkViolet;
moel@1
   170
      plotColorPalette[6] = Color.YellowGreen;
moel@1
   171
      plotColorPalette[7] = Color.SaddleBrown;
moel@111
   172
      plotColorPalette[8] = Color.RoyalBlue;
moel@111
   173
      plotColorPalette[9] = Color.DeepPink;
moel@111
   174
      plotColorPalette[10] = Color.MediumSeaGreen;
moel@111
   175
      plotColorPalette[11] = Color.Olive;
moel@111
   176
      plotColorPalette[12] = Color.Firebrick;
moel@327
   177
      
moel@327
   178
      computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
moel@327
   179
      computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);        
moel@327
   180
moel@327
   181
      computer.Open();
moel@327
   182
moel@327
   183
      timer.Enabled = true;
moel@1
   184
paulwerelds@223
   185
      showHiddenSensors = new UserOption("hiddenMenuItem", false,
paulwerelds@223
   186
        hiddenMenuItem, settings);
moel@156
   187
      showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
moel@156
   188
        treeModel.ForceVisible = showHiddenSensors.Value;
moel@156
   189
      };
moel@111
   190
paulwerelds@223
   191
      showValue = new UserOption("valueMenuItem", true, valueMenuItem,
paulwerelds@223
   192
        settings);
moel@156
   193
      showValue.Changed += delegate(object sender, EventArgs e) {
moel@156
   194
        treeView.Columns[1].IsVisible = showValue.Value;
moel@156
   195
      };
moel@122
   196
moel@165
   197
      showMin = new UserOption("minMenuItem", false, minMenuItem, settings);
moel@156
   198
      showMin.Changed += delegate(object sender, EventArgs e) {
moel@156
   199
        treeView.Columns[2].IsVisible = showMin.Value;
moel@156
   200
      };
moel@156
   201
moel@165
   202
      showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings);
moel@156
   203
      showMax.Changed += delegate(object sender, EventArgs e) {
moel@156
   204
        treeView.Columns[3].IsVisible = showMax.Value;
moel@156
   205
      };
moel@156
   206
paulwerelds@223
   207
      startMinimized = new UserOption("startMinMenuItem", false,
paulwerelds@223
   208
        startMinMenuItem, settings);
moel@156
   209
paulwerelds@223
   210
      minimizeToTray = new UserOption("minTrayMenuItem", true,
paulwerelds@223
   211
        minTrayMenuItem, settings);
moel@156
   212
      minimizeToTray.Changed += delegate(object sender, EventArgs e) {
moel@156
   213
        systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@156
   214
      };
moel@156
   215
paulwerelds@223
   216
      minimizeOnClose = new UserOption("minCloseMenuItem", false,
paulwerelds@223
   217
        minCloseMenuItem, settings);
paulwerelds@198
   218
paulwerelds@223
   219
      autoStart = new UserOption(null, startupManager.Startup,
paulwerelds@223
   220
        startupMenuItem, settings);
moel@156
   221
      autoStart.Changed += delegate(object sender, EventArgs e) {
moel@185
   222
        try {
moel@185
   223
          startupManager.Startup = autoStart.Value;
moel@185
   224
        } catch (InvalidOperationException) {
moel@185
   225
          MessageBox.Show("Updating the auto-startup option failed.", "Error", 
moel@185
   226
            MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@185
   227
          autoStart.Value = startupManager.Startup;
moel@185
   228
        }
moel@156
   229
      };
moel@156
   230
moel@360
   231
      readMainboardSensors = new UserOption("mainboardMenuItem", true, 
moel@360
   232
        mainboardMenuItem, settings);
moel@360
   233
      readMainboardSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   234
        computer.MainboardEnabled = readMainboardSensors.Value;
moel@360
   235
      };
moel@360
   236
moel@360
   237
      readCpuSensors = new UserOption("cpuMenuItem", true,
moel@360
   238
        cpuMenuItem, settings);
moel@360
   239
      readCpuSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   240
        computer.CPUEnabled = readCpuSensors.Value;
moel@360
   241
      };
moel@360
   242
moel@370
   243
      readRamSensors = new UserOption("ramMenuItem", true,
moel@370
   244
        ramMenuItem, settings);
moel@370
   245
      readRamSensors.Changed += delegate(object sender, EventArgs e) {
moel@370
   246
        computer.RAMEnabled = readRamSensors.Value;
moel@370
   247
      };
moel@370
   248
moel@360
   249
      readGpuSensors = new UserOption("gpuMenuItem", true,
moel@360
   250
        gpuMenuItem, settings);
moel@360
   251
      readGpuSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   252
        computer.GPUEnabled = readGpuSensors.Value;
moel@360
   253
      };
moel@360
   254
moel@360
   255
      readFanControllersSensors = new UserOption("fanControllerMenuItem", true,
moel@360
   256
        fanControllerMenuItem, settings);
moel@360
   257
      readFanControllersSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   258
        computer.FanControllerEnabled = readFanControllersSensors.Value;
moel@360
   259
      };
moel@360
   260
paulwerelds@223
   261
      readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
paulwerelds@223
   262
        settings);
moel@156
   263
      readHddSensors.Changed += delegate(object sender, EventArgs e) {
moel@156
   264
        computer.HDDEnabled = readHddSensors.Value;
moel@156
   265
      };
moel@156
   266
paulwerelds@223
   267
      showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
paulwerelds@223
   268
        settings);
moel@176
   269
      showGadget.Changed += delegate(object sender, EventArgs e) {
moel@202
   270
        if (gadget != null) 
moel@202
   271
          gadget.Visible = showGadget.Value;
moel@176
   272
      };
moel@176
   273
moel@299
   274
      celsiusMenuItem.Checked = 
moel@299
   275
        unitManager.TemperatureUnit == TemperatureUnit.Celsius;
moel@299
   276
      fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;
moel@55
   277
moel@348
   278
      server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085));
moel@387
   279
      if (server.PlatformNotSupported) {
moel@387
   280
        webMenuItemSeparator.Visible = false;
moel@387
   281
        webMenuItem.Visible = false;
moel@387
   282
      }
moel@387
   283
moel@348
   284
      runWebServer = new UserOption("runWebServerMenuItem", false,
moel@348
   285
        runWebServerMenuItem, settings);
moel@360
   286
      runWebServer.Changed += delegate(object sender, EventArgs e) {
moel@360
   287
        if (runWebServer.Value)
moel@387
   288
          server.StartHTTPListener();
moel@360
   289
        else
moel@386
   290
          server.StopHTTPListener();
moel@348
   291
      };
moel@348
   292
moel@420
   293
      logSensors = new UserOption("logSensorsMenuItem", false, logSensorsMenuItem,
moel@422
   294
        settings);
moel@422
   295
moel@422
   296
      loggingInterval = new UserRadioGroup("loggingInterval", 0,
moel@422
   297
        new[] { log1sMenuItem, log2sMenuItem, log5sMenuItem, log10sMenuItem,
moel@422
   298
        log30sMenuItem, log1minMenuItem, log2minMenuItem, log5minMenuItem, 
moel@422
   299
        log10minMenuItem, log30minMenuItem, log1hMenuItem, log2hMenuItem, 
moel@422
   300
        log6hMenuItem},
moel@422
   301
        settings);
moel@422
   302
      loggingInterval.Changed += (sender, e) => {
moel@422
   303
        switch (loggingInterval.Value) {
moel@422
   304
          case 0: logger.LoggingInterval = new TimeSpan(0, 0, 1); break;
moel@422
   305
          case 1: logger.LoggingInterval = new TimeSpan(0, 0, 2); break;
moel@422
   306
          case 2: logger.LoggingInterval = new TimeSpan(0, 0, 5); break;
moel@422
   307
          case 3: logger.LoggingInterval = new TimeSpan(0, 0, 10); break;
moel@422
   308
          case 4: logger.LoggingInterval = new TimeSpan(0, 0, 30); break;
moel@422
   309
          case 5: logger.LoggingInterval = new TimeSpan(0, 1, 0); break;
moel@422
   310
          case 6: logger.LoggingInterval = new TimeSpan(0, 2, 0); break;
moel@422
   311
          case 7: logger.LoggingInterval = new TimeSpan(0, 5, 0); break;
moel@422
   312
          case 8: logger.LoggingInterval = new TimeSpan(0, 10, 0); break;
moel@422
   313
          case 9: logger.LoggingInterval = new TimeSpan(0, 30, 0); break;
moel@422
   314
          case 10: logger.LoggingInterval = new TimeSpan(1, 0, 0); break;
moel@422
   315
          case 11: logger.LoggingInterval = new TimeSpan(2, 0, 0); break;
moel@422
   316
          case 12: logger.LoggingInterval = new TimeSpan(6, 0, 0); break;
moel@422
   317
        }
moel@422
   318
      };
moel@420
   319
moel@295
   320
      InitializePlotForm();
moel@295
   321
StephaneLenclud@435
   322
StephaneLenclud@436
   323
      soundGraphDisplay.Init();
StephaneLenclud@436
   324
StephaneLenclud@435
   325
StephaneLenclud@435
   326
moel@142
   327
      startupMenuItem.Visible = startupManager.IsAvailable;
moel@125
   328
      
moel@55
   329
      if (startMinMenuItem.Checked) {
moel@82
   330
        if (!minTrayMenuItem.Checked) {
moel@55
   331
          WindowState = FormWindowState.Minimized;
moel@55
   332
          Show();
moel@55
   333
        }
moel@55
   334
      } else {
moel@55
   335
        Show();
moel@55
   336
      }
moel@70
   337
moel@71
   338
      // Create a handle, otherwise calling Close() does not fire FormClosed     
moel@71
   339
      IntPtr handle = Handle;
moel@128
   340
moel@128
   341
      // Make sure the settings are saved when the user logs off
paulwerelds@223
   342
      Microsoft.Win32.SystemEvents.SessionEnded += delegate {
moel@380
   343
        computer.Close();
paulwerelds@223
   344
        SaveConfiguration();
moel@348
   345
        if (runWebServer.Value) 
moel@387
   346
          server.Quit();
moel@304
   347
      };
moel@1
   348
    }
moel@295
   349
moel@295
   350
    private void InitializePlotForm() {
moel@295
   351
      plotForm = new Form();
moel@295
   352
      plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
moel@295
   353
      plotForm.ShowInTaskbar = false;
moel@295
   354
      plotForm.StartPosition = FormStartPosition.Manual;
moel@295
   355
      this.AddOwnedForm(plotForm);
moel@295
   356
      plotForm.Bounds = new Rectangle {
moel@295
   357
        X = settings.GetValue("plotForm.Location.X", -100000),
moel@295
   358
        Y = settings.GetValue("plotForm.Location.Y", 100),
moel@295
   359
        Width = settings.GetValue("plotForm.Width", 600),
moel@295
   360
        Height = settings.GetValue("plotForm.Height", 400)
moel@295
   361
      };
moel@295
   362
moel@295
   363
      showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
moel@295
   364
      plotLocation = new UserRadioGroup("plotLocation", 0,
moel@295
   365
        new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
moel@295
   366
        settings);
moel@295
   367
moel@295
   368
      showPlot.Changed += delegate(object sender, EventArgs e) {
moel@295
   369
        if (plotLocation.Value == 0) {
moel@295
   370
          if (showPlot.Value && this.Visible)
moel@295
   371
            plotForm.Show();
moel@295
   372
          else
moel@295
   373
            plotForm.Hide();
moel@295
   374
        } else {
moel@295
   375
          splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   376
        }
moel@295
   377
        treeView.Invalidate();
moel@295
   378
      };
moel@295
   379
      plotLocation.Changed += delegate(object sender, EventArgs e) {
moel@295
   380
        switch (plotLocation.Value) {
moel@295
   381
          case 0:
moel@295
   382
            splitContainer.Panel2.Controls.Clear();
moel@295
   383
            splitContainer.Panel2Collapsed = true;
moel@295
   384
            plotForm.Controls.Add(plotPanel);
moel@295
   385
            if (showPlot.Value && this.Visible)
moel@295
   386
              plotForm.Show();
moel@295
   387
            break;
moel@295
   388
          case 1:
moel@295
   389
            plotForm.Controls.Clear();
moel@295
   390
            plotForm.Hide();
moel@295
   391
            splitContainer.Orientation = Orientation.Horizontal;
moel@295
   392
            splitContainer.Panel2.Controls.Add(plotPanel);
moel@295
   393
            splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   394
            break;
moel@295
   395
          case 2:
moel@295
   396
            plotForm.Controls.Clear();
moel@295
   397
            plotForm.Hide();
moel@295
   398
            splitContainer.Orientation = Orientation.Vertical;
moel@295
   399
            splitContainer.Panel2.Controls.Add(plotPanel);
moel@295
   400
            splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   401
            break;
moel@295
   402
        }
moel@295
   403
      };
moel@297
   404
moel@297
   405
      plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) {
moel@297
   406
        if (e.CloseReason == CloseReason.UserClosing) {
moel@297
   407
          // just switch off the plotting when the user closes the form
moel@297
   408
          if (plotLocation.Value == 0) {
moel@297
   409
            showPlot.Value = false;
moel@297
   410
          }
moel@297
   411
          e.Cancel = true;
moel@295
   412
        }
moel@295
   413
      };
moel@297
   414
moel@295
   415
      EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
moel@295
   416
        if (plotForm.WindowState != FormWindowState.Minimized) {
moel@295
   417
          settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
moel@295
   418
          settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
moel@295
   419
          settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
moel@295
   420
          settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
moel@295
   421
        }
moel@295
   422
      };
moel@295
   423
      plotForm.Move += moveOrResizePlotForm;
moel@295
   424
      plotForm.Resize += moveOrResizePlotForm;
moel@295
   425
moel@295
   426
      plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
moel@295
   427
        Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
moel@295
   428
        Screen screen = Screen.FromRectangle(bounds);
moel@295
   429
        Rectangle intersection =
moel@295
   430
          Rectangle.Intersect(screen.WorkingArea, bounds);
moel@295
   431
        if (intersection.Width < Math.Min(16, bounds.Width) ||
moel@295
   432
            intersection.Height < Math.Min(16, bounds.Height)) {
moel@295
   433
          plotForm.Location = new Point(
moel@295
   434
            screen.WorkingArea.Width / 2 - bounds.Width / 2,
moel@295
   435
            screen.WorkingArea.Height / 2 - bounds.Height / 2);
moel@295
   436
        }
moel@295
   437
      };
moel@295
   438
moel@295
   439
      this.VisibleChanged += delegate(object sender, EventArgs e) {
moel@295
   440
        if (this.Visible && showPlot.Value && plotLocation.Value == 0)
moel@295
   441
          plotForm.Show();
moel@295
   442
        else
moel@295
   443
          plotForm.Hide();
moel@295
   444
      };
moel@295
   445
    }
moel@360
   446
moel@360
   447
    private void InsertSorted(Collection<Node> nodes, HardwareNode node) {
moel@360
   448
      int i = 0;
moel@360
   449
      while (i < nodes.Count && nodes[i] is HardwareNode &&
moel@360
   450
        ((HardwareNode)nodes[i]).Hardware.HardwareType < 
moel@360
   451
          node.Hardware.HardwareType)
moel@360
   452
        i++;
moel@360
   453
      nodes.Insert(i, node);
moel@360
   454
    }
moel@128
   455
    
moel@64
   456
    private void SubHardwareAdded(IHardware hardware, Node node) {
moel@327
   457
      HardwareNode hardwareNode = 
moel@327
   458
        new HardwareNode(hardware, settings, unitManager);
moel@327
   459
      hardwareNode.PlotSelectionChanged += PlotSelectionChanged;
moel@327
   460
moel@360
   461
      InsertSorted(node.Nodes, hardwareNode);
moel@360
   462
moel@64
   463
      foreach (IHardware subHardware in hardware.SubHardware)
moel@64
   464
        SubHardwareAdded(subHardware, hardwareNode);  
moel@64
   465
    }
moel@64
   466
moel@327
   467
    private void HardwareAdded(IHardware hardware) {      
moel@327
   468
      SubHardwareAdded(hardware, root);
moel@327
   469
      PlotSelectionChanged(this, null);
moel@1
   470
    }
moel@1
   471
moel@327
   472
    private void HardwareRemoved(IHardware hardware) {
moel@327
   473
      List<HardwareNode> nodesToRemove = new List<HardwareNode>();
moel@28
   474
      foreach (Node node in root.Nodes) {
moel@28
   475
        HardwareNode hardwareNode = node as HardwareNode;
moel@28
   476
        if (hardwareNode != null && hardwareNode.Hardware == hardware)
moel@327
   477
          nodesToRemove.Add(hardwareNode);
moel@28
   478
      }
moel@327
   479
      foreach (HardwareNode hardwareNode in nodesToRemove) {
moel@327
   480
        root.Nodes.Remove(hardwareNode);
moel@327
   481
        hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
moel@327
   482
      }
moel@327
   483
      PlotSelectionChanged(this, null);
moel@1
   484
    }
moel@1
   485
moel@111
   486
    private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {       
moel@111
   487
      Node node = e.Node.Tag as Node;
moel@111
   488
      if (node != null) {
moel@1
   489
        Color color;
moel@111
   490
        if (node.IsVisible) {
moel@111
   491
          SensorNode sensorNode = node as SensorNode;
moel@111
   492
          if (plotMenuItem.Checked && sensorNode != null &&
moel@111
   493
            sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
moel@111
   494
            e.TextColor = color;
moel@111
   495
        } else {
moel@111
   496
          e.TextColor = Color.DarkGray;
moel@111
   497
        }
moel@1
   498
      }
moel@1
   499
    }
moel@1
   500
moel@327
   501
    private void PlotSelectionChanged(object sender, EventArgs e) {
moel@1
   502
      List<ISensor> selected = new List<ISensor>();
moel@1
   503
      IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
moel@1
   504
      int colorIndex = 0;
moel@1
   505
      foreach (TreeNodeAdv node in treeView.AllNodes) {
moel@1
   506
        SensorNode sensorNode = node.Tag as SensorNode;
moel@395
   507
        if (sensorNode != null) {
moel@1
   508
          if (sensorNode.Plot) {
moel@1
   509
            colors.Add(sensorNode.Sensor,
moel@1
   510
              plotColorPalette[colorIndex % plotColorPalette.Length]);
moel@1
   511
            selected.Add(sensorNode.Sensor);
moel@1
   512
          }
moel@1
   513
          colorIndex++;
moel@1
   514
        }
moel@1
   515
      }
moel@1
   516
      sensorPlotColors = colors;
moel@1
   517
      plotPanel.SetSensors(selected, colors);
moel@1
   518
    }
moel@1
   519
paulwerelds@223
   520
    private void nodeTextBoxText_EditorShowing(object sender,
paulwerelds@223
   521
      CancelEventArgs e) 
moel@141
   522
    {
moel@141
   523
      e.Cancel = !(treeView.CurrentNode != null &&
moel@275
   524
        (treeView.CurrentNode.Tag is SensorNode || 
moel@275
   525
         treeView.CurrentNode.Tag is HardwareNode));
moel@141
   526
    }
moel@141
   527
moel@1
   528
    private void nodeCheckBox_IsVisibleValueNeeded(object sender, 
moel@1
   529
      NodeControlValueEventArgs e) {
moel@1
   530
      SensorNode node = e.Node.Tag as SensorNode;
moel@395
   531
      e.Value = (node != null) && plotMenuItem.Checked;
moel@1
   532
    }
moel@1
   533
moel@133
   534
    private void exitClick(object sender, EventArgs e) {
paulwerelds@198
   535
      Close();
moel@1
   536
    }
moel@1
   537
moel@421
   538
    private int delayCount = 0;
moel@86
   539
    private void timer_Tick(object sender, EventArgs e) {
moel@110
   540
      computer.Accept(updateVisitor);
moel@1
   541
      treeView.Invalidate();
moel@395
   542
      plotPanel.InvalidatePlot();
paulwerelds@223
   543
      systemTray.Redraw();
moel@202
   544
      if (gadget != null)
moel@202
   545
        gadget.Redraw();
paulwerelds@223
   546
paulwerelds@223
   547
      if (wmiProvider != null)
paulwerelds@223
   548
        wmiProvider.Update();
moel@420
   549
StephaneLenclud@436
   550
      if (soundGraphDisplay != null)
StephaneLenclud@436
   551
      {
StephaneLenclud@436
   552
          displayTick=!displayTick;
StephaneLenclud@436
   553
          if (displayTick)
StephaneLenclud@436
   554
          {
StephaneLenclud@436
   555
              soundGraphDisplay.SetText("       ---", "");
StephaneLenclud@436
   556
          }
StephaneLenclud@436
   557
          else
StephaneLenclud@436
   558
          {
StephaneLenclud@436
   559
              soundGraphDisplay.SetText("       -+-", "");
StephaneLenclud@436
   560
          }
StephaneLenclud@436
   561
      }  
StephaneLenclud@436
   562
moel@421
   563
moel@431
   564
      if (logSensors != null && logSensors.Value && delayCount >= 4)
moel@420
   565
        logger.Log();
moel@421
   566
moel@421
   567
      if (delayCount < 4)
moel@421
   568
        delayCount++;
moel@1
   569
    }
moel@1
   570
moel@128
   571
    private void SaveConfiguration() {
moel@395
   572
      plotPanel.SetCurrentSettings();
moel@128
   573
      foreach (TreeColumn column in treeView.Columns)
moel@166
   574
        settings.SetValue("treeView.Columns." + column.Header + ".Width",
moel@113
   575
          column.Width);
moel@113
   576
moel@348
   577
      this.settings.SetValue("listenerPort", server.ListenerPort);
moel@348
   578
moel@212
   579
      string fileName = Path.ChangeExtension(
moel@212
   580
          System.Windows.Forms.Application.ExecutablePath, ".config");
moel@212
   581
      try {
moel@212
   582
        settings.Save(fileName);
moel@212
   583
      } catch (UnauthorizedAccessException) {
paulwerelds@214
   584
        MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
moel@284
   585
          "The current settings could not be saved.",
moel@284
   586
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@284
   587
      } catch (IOException) {
moel@284
   588
        MessageBox.Show("The path '" + fileName + "' is not writeable. " +
moel@284
   589
          "The current settings could not be saved.",
moel@212
   590
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@212
   591
      }
moel@128
   592
    }
moel@128
   593
paulwerelds@214
   594
    private void MainForm_Load(object sender, EventArgs e) {
paulwerelds@214
   595
      Rectangle newBounds = new Rectangle {
paulwerelds@214
   596
        X = settings.GetValue("mainForm.Location.X", Location.X),
paulwerelds@214
   597
        Y = settings.GetValue("mainForm.Location.Y", Location.Y),
paulwerelds@214
   598
        Width = settings.GetValue("mainForm.Width", 470),
paulwerelds@214
   599
        Height = settings.GetValue("mainForm.Height", 640)
paulwerelds@214
   600
      };
paulwerelds@214
   601
paulwerelds@223
   602
      Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
paulwerelds@214
   603
        int.MinValue, int.MinValue);
paulwerelds@214
   604
paulwerelds@214
   605
      foreach (Screen screen in Screen.AllScreens)
paulwerelds@223
   606
        fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
paulwerelds@214
   607
paulwerelds@223
   608
      Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
paulwerelds@214
   609
      if (intersection.Width < 20 || intersection.Height < 20 ||
paulwerelds@214
   610
        !settings.Contains("mainForm.Location.X")
paulwerelds@214
   611
      ) {
paulwerelds@214
   612
        newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
paulwerelds@214
   613
                      (newBounds.Width/2);
paulwerelds@214
   614
paulwerelds@214
   615
        newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
paulwerelds@214
   616
                      (newBounds.Height / 2);
paulwerelds@214
   617
      }
paulwerelds@214
   618
paulwerelds@214
   619
      this.Bounds = newBounds;
paulwerelds@214
   620
    }
paulwerelds@214
   621
    
paulwerelds@214
   622
    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
moel@298
   623
      Visible = false;      
moel@262
   624
      systemTray.IsMainIconEnabled = false;
moel@262
   625
      timer.Enabled = false;            
moel@28
   626
      computer.Close();
moel@298
   627
      SaveConfiguration();
moel@348
   628
      if (runWebServer.Value)
moel@348
   629
          server.Quit();
moel@262
   630
      systemTray.Dispose();
StephaneLenclud@433
   631
      soundGraphDisplay.Dispose();
moel@1
   632
    }
moel@1
   633
moel@156
   634
    private void aboutMenuItem_Click(object sender, EventArgs e) {
moel@1
   635
      new AboutBox().ShowDialog();
moel@1
   636
    }
moel@1
   637
moel@1
   638
    private void treeView_Click(object sender, EventArgs e) {
moel@275
   639
moel@1
   640
      MouseEventArgs m = e as MouseEventArgs;
moel@1
   641
      if (m == null || m.Button != MouseButtons.Right)
moel@1
   642
        return;
moel@1
   643
paulwerelds@223
   644
      NodeControlInfo info = treeView.GetNodeControlInfoAt(
paulwerelds@223
   645
        new Point(m.X, m.Y)
paulwerelds@223
   646
      );
moel@156
   647
      treeView.SelectedNode = info.Node;
moel@156
   648
      if (info.Node != null) {
moel@40
   649
        SensorNode node = info.Node.Tag as SensorNode;
moel@40
   650
        if (node != null && node.Sensor != null) {
moel@275
   651
          treeContextMenu.MenuItems.Clear();
moel@63
   652
          if (node.Sensor.Parameters.Length > 0) {
moel@156
   653
            MenuItem item = new MenuItem("Parameters...");
moel@63
   654
            item.Click += delegate(object obj, EventArgs args) {
moel@63
   655
              ShowParameterForm(node.Sensor);
moel@63
   656
            };
moel@275
   657
            treeContextMenu.MenuItems.Add(item);
moel@63
   658
          }
moel@156
   659
          if (nodeTextBoxText.EditEnabled) {
moel@156
   660
            MenuItem item = new MenuItem("Rename");
moel@141
   661
            item.Click += delegate(object obj, EventArgs args) {
moel@156
   662
              nodeTextBoxText.BeginEdit();
moel@141
   663
            };
moel@275
   664
            treeContextMenu.MenuItems.Add(item);
moel@176
   665
          }
moel@111
   666
          if (node.IsVisible) {
moel@156
   667
            MenuItem item = new MenuItem("Hide");
moel@111
   668
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   669
              node.IsVisible = false;
moel@111
   670
            };
moel@275
   671
            treeContextMenu.MenuItems.Add(item);
moel@111
   672
          } else {
moel@156
   673
            MenuItem item = new MenuItem("Unhide");
moel@111
   674
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   675
              node.IsVisible = true;
moel@111
   676
            };
moel@275
   677
            treeContextMenu.MenuItems.Add(item);
moel@176
   678
          }
moel@275
   679
          treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@178
   680
          {
moel@178
   681
            MenuItem item = new MenuItem("Show in Tray");
moel@178
   682
            item.Checked = systemTray.Contains(node.Sensor);
moel@178
   683
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   684
              if (item.Checked)
moel@178
   685
                systemTray.Remove(node.Sensor);
moel@178
   686
              else
moel@178
   687
                systemTray.Add(node.Sensor, true);
moel@178
   688
            };
moel@275
   689
            treeContextMenu.MenuItems.Add(item);
moel@178
   690
          }
StephaneLenclud@433
   691
          {
StephaneLenclud@433
   692
              MenuItem item = new MenuItem("Show in iMON FrontView");
StephaneLenclud@433
   693
              item.Checked = systemTray.Contains(node.Sensor);
StephaneLenclud@433
   694
              item.Click += delegate(object obj, EventArgs args)
StephaneLenclud@433
   695
              {
StephaneLenclud@433
   696
                  if (item.Checked)
StephaneLenclud@433
   697
                      soundGraphDisplay.Remove(node.Sensor);
StephaneLenclud@433
   698
                  else
StephaneLenclud@433
   699
                      soundGraphDisplay.Add(node.Sensor, true);
StephaneLenclud@433
   700
              };
StephaneLenclud@433
   701
              treeContextMenu.MenuItems.Add(item);
StephaneLenclud@433
   702
          }
moel@211
   703
          if (gadget != null) {
moel@178
   704
            MenuItem item = new MenuItem("Show in Gadget");
moel@178
   705
            item.Checked = gadget.Contains(node.Sensor);
moel@178
   706
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   707
              if (item.Checked) {
moel@178
   708
                gadget.Remove(node.Sensor);
moel@178
   709
              } else {
moel@178
   710
                gadget.Add(node.Sensor);
moel@178
   711
              }
moel@178
   712
            };
moel@275
   713
            treeContextMenu.MenuItems.Add(item);
moel@178
   714
          }
moel@247
   715
          if (node.Sensor.Control != null) {
moel@275
   716
            treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@247
   717
            IControl control = node.Sensor.Control;
moel@247
   718
            MenuItem controlItem = new MenuItem("Control");
moel@247
   719
            MenuItem defaultItem = new MenuItem("Default");
moel@247
   720
            defaultItem.Checked = control.ControlMode == ControlMode.Default;
moel@247
   721
            controlItem.MenuItems.Add(defaultItem);
moel@247
   722
            defaultItem.Click += delegate(object obj, EventArgs args) {
moel@247
   723
              control.SetDefault();
moel@247
   724
            };
moel@275
   725
            MenuItem manualItem = new MenuItem("Manual");
moel@247
   726
            controlItem.MenuItems.Add(manualItem);
moel@247
   727
            manualItem.Checked = control.ControlMode == ControlMode.Software;
moel@247
   728
            for (int i = 0; i <= 100; i += 5) {
moel@247
   729
              if (i <= control.MaxSoftwareValue &&
moel@275
   730
                  i >= control.MinSoftwareValue) {
moel@247
   731
                MenuItem item = new MenuItem(i + " %");
moel@378
   732
                item.RadioCheck = true;
moel@247
   733
                manualItem.MenuItems.Add(item);
moel@247
   734
                item.Checked = control.ControlMode == ControlMode.Software &&
moel@247
   735
                  Math.Round(control.SoftwareValue) == i;
moel@247
   736
                int softwareValue = i;
moel@247
   737
                item.Click += delegate(object obj, EventArgs args) {
moel@247
   738
                  control.SetSoftware(softwareValue);
moel@247
   739
                };
moel@247
   740
              }
moel@247
   741
            }
moel@275
   742
            treeContextMenu.MenuItems.Add(controlItem);
moel@247
   743
          }
moel@176
   744
moel@275
   745
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@275
   746
        }
moel@275
   747
moel@275
   748
        HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
moel@275
   749
        if (hardwareNode != null && hardwareNode.Hardware != null) {
moel@275
   750
          treeContextMenu.MenuItems.Clear();
moel@275
   751
moel@275
   752
          if (nodeTextBoxText.EditEnabled) {
moel@275
   753
            MenuItem item = new MenuItem("Rename");
moel@275
   754
            item.Click += delegate(object obj, EventArgs args) {
moel@275
   755
              nodeTextBoxText.BeginEdit();
moel@275
   756
            };
moel@275
   757
            treeContextMenu.MenuItems.Add(item);
moel@275
   758
          }
moel@275
   759
moel@275
   760
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@40
   761
        }
moel@40
   762
      }
moel@1
   763
    }
moel@1
   764
moel@156
   765
    private void saveReportMenuItem_Click(object sender, EventArgs e) {
moel@83
   766
      string report = computer.GetReport();
moel@83
   767
      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
moel@83
   768
        using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
moel@83
   769
          w.Write(report);
moel@83
   770
        }
moel@83
   771
      }
moel@1
   772
    }
moel@1
   773
moel@82
   774
    private void SysTrayHideShow() {
moel@82
   775
      Visible = !Visible;
moel@82
   776
      if (Visible)
moel@82
   777
        Activate();    
moel@27
   778
    }
moel@27
   779
moel@27
   780
    protected override void WndProc(ref Message m) {
moel@27
   781
      const int WM_SYSCOMMAND = 0x112;
moel@27
   782
      const int SC_MINIMIZE = 0xF020;
paulwerelds@198
   783
      const int SC_CLOSE = 0xF060;
paulwerelds@198
   784
StephaneLenclud@436
   785
 
StephaneLenclud@436
   786
      if (minimizeToTray.Value &&
StephaneLenclud@435
   787
        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE)
StephaneLenclud@435
   788
      {
paulwerelds@198
   789
          SysTrayHideShow();
StephaneLenclud@435
   790
      }
StephaneLenclud@435
   791
      else if (minimizeOnClose.Value &&
StephaneLenclud@435
   792
      m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE)
StephaneLenclud@435
   793
      {
StephaneLenclud@435
   794
          /*
StephaneLenclud@435
   795
           * Apparently the user wants to minimize rather than close
StephaneLenclud@435
   796
           * Now we still need to check if we're going to the tray or not
StephaneLenclud@435
   797
           * 
StephaneLenclud@435
   798
           * Note: the correct way to do this would be to send out SC_MINIMIZE,
StephaneLenclud@435
   799
           * but since the code here is so simple,
StephaneLenclud@435
   800
           * that would just be a waste of time.
StephaneLenclud@435
   801
           */
StephaneLenclud@435
   802
          if (minimizeToTray.Value)
StephaneLenclud@435
   803
              SysTrayHideShow();
StephaneLenclud@435
   804
          else
StephaneLenclud@435
   805
              WindowState = FormWindowState.Minimized;
StephaneLenclud@435
   806
      }
StephaneLenclud@435
   807
      else
StephaneLenclud@435
   808
      {
StephaneLenclud@435
   809
          base.WndProc(ref m);
moel@27
   810
      }
moel@27
   811
    }
moel@27
   812
moel@82
   813
    private void hideShowClick(object sender, EventArgs e) {
moel@82
   814
      SysTrayHideShow();
moel@27
   815
    }
moel@27
   816
moel@63
   817
    private void ShowParameterForm(ISensor sensor) {
moel@63
   818
      ParameterForm form = new ParameterForm();
moel@63
   819
      form.Parameters = sensor.Parameters;
moel@63
   820
      form.captionLabel.Text = sensor.Name;
moel@63
   821
      form.ShowDialog();
moel@63
   822
    }
moel@63
   823
moel@63
   824
    private void treeView_NodeMouseDoubleClick(object sender, 
moel@63
   825
      TreeNodeAdvMouseEventArgs e) {
moel@63
   826
      SensorNode node = e.Node.Tag as SensorNode;
moel@63
   827
      if (node != null && node.Sensor != null && 
moel@63
   828
        node.Sensor.Parameters.Length > 0) {
moel@63
   829
        ShowParameterForm(node.Sensor);
moel@63
   830
      }
moel@63
   831
    }
moel@82
   832
moel@299
   833
    private void celsiusMenuItem_Click(object sender, EventArgs e) {
moel@299
   834
      celsiusMenuItem.Checked = true;
moel@156
   835
      fahrenheitMenuItem.Checked = false;
moel@299
   836
      unitManager.TemperatureUnit = TemperatureUnit.Celsius;
moel@122
   837
    }
moel@122
   838
moel@156
   839
    private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
moel@299
   840
      celsiusMenuItem.Checked = false;
moel@156
   841
      fahrenheitMenuItem.Checked = true;
moel@165
   842
      unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
moel@122
   843
    }
moel@150
   844
moel@156
   845
    private void sumbitReportMenuItem_Click(object sender, EventArgs e) 
moel@150
   846
    {
moel@150
   847
      ReportForm form = new ReportForm();
moel@150
   848
      form.Report = computer.GetReport();
moel@150
   849
      form.ShowDialog();      
moel@150
   850
    }
moel@151
   851
moel@151
   852
    private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
moel@159
   853
      computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
moel@159
   854
        sensor.ResetMin();
moel@159
   855
        sensor.ResetMax();
moel@159
   856
      }));
moel@151
   857
    }
moel@241
   858
moel@241
   859
    private void MainForm_MoveOrResize(object sender, EventArgs e) {
moel@241
   860
      if (WindowState != FormWindowState.Minimized) {
moel@241
   861
        settings.SetValue("mainForm.Location.X", Bounds.X);
moel@241
   862
        settings.SetValue("mainForm.Location.Y", Bounds.Y);
moel@241
   863
        settings.SetValue("mainForm.Width", Bounds.Width);
moel@241
   864
        settings.SetValue("mainForm.Height", Bounds.Height);
moel@241
   865
      }
moel@241
   866
    }
moel@262
   867
moel@262
   868
    private void resetClick(object sender, EventArgs e) {
moel@262
   869
      // disable the fallback MainIcon during reset, otherwise icon visibility
moel@262
   870
      // might be lost 
moel@262
   871
      systemTray.IsMainIconEnabled = false;
moel@262
   872
      computer.Close();
moel@262
   873
      computer.Open();
moel@262
   874
      // restore the MainIcon setting
moel@262
   875
      systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@262
   876
    }
moel@287
   877
moel@287
   878
    private void treeView_MouseMove(object sender, MouseEventArgs e) {
moel@288
   879
      selectionDragging = selectionDragging &
moel@288
   880
        (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0; 
moel@288
   881
moel@288
   882
      if (selectionDragging)
moel@288
   883
        treeView.SelectedNode = treeView.GetNodeAt(e.Location);     
moel@288
   884
    }
moel@288
   885
moel@288
   886
    private void treeView_MouseDown(object sender, MouseEventArgs e) {
moel@288
   887
      selectionDragging = true;
moel@288
   888
    }
moel@288
   889
moel@288
   890
    private void treeView_MouseUp(object sender, MouseEventArgs e) {
moel@288
   891
      selectionDragging = false;
moel@287
   892
    }
moel@348
   893
moel@348
   894
    private void serverPortMenuItem_Click(object sender, EventArgs e) {
moel@348
   895
      new PortForm(this).ShowDialog();
moel@348
   896
    }
moel@348
   897
moel@348
   898
    public HttpServer Server {
moel@348
   899
      get { return server; }
moel@348
   900
    }
moel@348
   901
moel@1
   902
  }
moel@1
   903
}