GUI/MainForm.cs
author StephaneLenclud
Sat, 13 Apr 2013 00:43:25 +0200
branchMiniDisplay
changeset 438 f590956d3234
parent 436 e9aefd454d1e
child 440 f43bab5fc81e
permissions -rw-r--r--
Sensors can now be displayed in FrontView.
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@438
   552
          soundGraphDisplay.Redraw();
StephaneLenclud@438
   553
          /*
StephaneLenclud@436
   554
          displayTick=!displayTick;
StephaneLenclud@436
   555
          if (displayTick)
StephaneLenclud@436
   556
          {
StephaneLenclud@436
   557
              soundGraphDisplay.SetText("       ---", "");
StephaneLenclud@436
   558
          }
StephaneLenclud@436
   559
          else
StephaneLenclud@436
   560
          {
StephaneLenclud@436
   561
              soundGraphDisplay.SetText("       -+-", "");
StephaneLenclud@436
   562
          }
StephaneLenclud@438
   563
          */
StephaneLenclud@436
   564
      }  
StephaneLenclud@436
   565
moel@421
   566
moel@431
   567
      if (logSensors != null && logSensors.Value && delayCount >= 4)
moel@420
   568
        logger.Log();
moel@421
   569
moel@421
   570
      if (delayCount < 4)
moel@421
   571
        delayCount++;
moel@1
   572
    }
moel@1
   573
moel@128
   574
    private void SaveConfiguration() {
moel@395
   575
      plotPanel.SetCurrentSettings();
moel@128
   576
      foreach (TreeColumn column in treeView.Columns)
moel@166
   577
        settings.SetValue("treeView.Columns." + column.Header + ".Width",
moel@113
   578
          column.Width);
moel@113
   579
moel@348
   580
      this.settings.SetValue("listenerPort", server.ListenerPort);
moel@348
   581
moel@212
   582
      string fileName = Path.ChangeExtension(
moel@212
   583
          System.Windows.Forms.Application.ExecutablePath, ".config");
moel@212
   584
      try {
moel@212
   585
        settings.Save(fileName);
moel@212
   586
      } catch (UnauthorizedAccessException) {
paulwerelds@214
   587
        MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
moel@284
   588
          "The current settings could not be saved.",
moel@284
   589
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@284
   590
      } catch (IOException) {
moel@284
   591
        MessageBox.Show("The path '" + fileName + "' is not writeable. " +
moel@284
   592
          "The current settings could not be saved.",
moel@212
   593
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@212
   594
      }
moel@128
   595
    }
moel@128
   596
paulwerelds@214
   597
    private void MainForm_Load(object sender, EventArgs e) {
paulwerelds@214
   598
      Rectangle newBounds = new Rectangle {
paulwerelds@214
   599
        X = settings.GetValue("mainForm.Location.X", Location.X),
paulwerelds@214
   600
        Y = settings.GetValue("mainForm.Location.Y", Location.Y),
paulwerelds@214
   601
        Width = settings.GetValue("mainForm.Width", 470),
paulwerelds@214
   602
        Height = settings.GetValue("mainForm.Height", 640)
paulwerelds@214
   603
      };
paulwerelds@214
   604
paulwerelds@223
   605
      Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
paulwerelds@214
   606
        int.MinValue, int.MinValue);
paulwerelds@214
   607
paulwerelds@214
   608
      foreach (Screen screen in Screen.AllScreens)
paulwerelds@223
   609
        fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
paulwerelds@214
   610
paulwerelds@223
   611
      Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
paulwerelds@214
   612
      if (intersection.Width < 20 || intersection.Height < 20 ||
paulwerelds@214
   613
        !settings.Contains("mainForm.Location.X")
paulwerelds@214
   614
      ) {
paulwerelds@214
   615
        newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
paulwerelds@214
   616
                      (newBounds.Width/2);
paulwerelds@214
   617
paulwerelds@214
   618
        newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
paulwerelds@214
   619
                      (newBounds.Height / 2);
paulwerelds@214
   620
      }
paulwerelds@214
   621
paulwerelds@214
   622
      this.Bounds = newBounds;
paulwerelds@214
   623
    }
paulwerelds@214
   624
    
paulwerelds@214
   625
    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
moel@298
   626
      Visible = false;      
moel@262
   627
      systemTray.IsMainIconEnabled = false;
moel@262
   628
      timer.Enabled = false;            
moel@28
   629
      computer.Close();
moel@298
   630
      SaveConfiguration();
moel@348
   631
      if (runWebServer.Value)
moel@348
   632
          server.Quit();
moel@262
   633
      systemTray.Dispose();
StephaneLenclud@433
   634
      soundGraphDisplay.Dispose();
moel@1
   635
    }
moel@1
   636
moel@156
   637
    private void aboutMenuItem_Click(object sender, EventArgs e) {
moel@1
   638
      new AboutBox().ShowDialog();
moel@1
   639
    }
moel@1
   640
moel@1
   641
    private void treeView_Click(object sender, EventArgs e) {
moel@275
   642
moel@1
   643
      MouseEventArgs m = e as MouseEventArgs;
moel@1
   644
      if (m == null || m.Button != MouseButtons.Right)
moel@1
   645
        return;
moel@1
   646
paulwerelds@223
   647
      NodeControlInfo info = treeView.GetNodeControlInfoAt(
paulwerelds@223
   648
        new Point(m.X, m.Y)
paulwerelds@223
   649
      );
moel@156
   650
      treeView.SelectedNode = info.Node;
moel@156
   651
      if (info.Node != null) {
moel@40
   652
        SensorNode node = info.Node.Tag as SensorNode;
moel@40
   653
        if (node != null && node.Sensor != null) {
moel@275
   654
          treeContextMenu.MenuItems.Clear();
moel@63
   655
          if (node.Sensor.Parameters.Length > 0) {
moel@156
   656
            MenuItem item = new MenuItem("Parameters...");
moel@63
   657
            item.Click += delegate(object obj, EventArgs args) {
moel@63
   658
              ShowParameterForm(node.Sensor);
moel@63
   659
            };
moel@275
   660
            treeContextMenu.MenuItems.Add(item);
moel@63
   661
          }
moel@156
   662
          if (nodeTextBoxText.EditEnabled) {
moel@156
   663
            MenuItem item = new MenuItem("Rename");
moel@141
   664
            item.Click += delegate(object obj, EventArgs args) {
moel@156
   665
              nodeTextBoxText.BeginEdit();
moel@141
   666
            };
moel@275
   667
            treeContextMenu.MenuItems.Add(item);
moel@176
   668
          }
moel@111
   669
          if (node.IsVisible) {
moel@156
   670
            MenuItem item = new MenuItem("Hide");
moel@111
   671
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   672
              node.IsVisible = false;
moel@111
   673
            };
moel@275
   674
            treeContextMenu.MenuItems.Add(item);
moel@111
   675
          } else {
moel@156
   676
            MenuItem item = new MenuItem("Unhide");
moel@111
   677
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   678
              node.IsVisible = true;
moel@111
   679
            };
moel@275
   680
            treeContextMenu.MenuItems.Add(item);
moel@176
   681
          }
moel@275
   682
          treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@178
   683
          {
moel@178
   684
            MenuItem item = new MenuItem("Show in Tray");
moel@178
   685
            item.Checked = systemTray.Contains(node.Sensor);
moel@178
   686
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   687
              if (item.Checked)
moel@178
   688
                systemTray.Remove(node.Sensor);
moel@178
   689
              else
moel@178
   690
                systemTray.Add(node.Sensor, true);
moel@178
   691
            };
moel@275
   692
            treeContextMenu.MenuItems.Add(item);
moel@178
   693
          }
StephaneLenclud@433
   694
          {
StephaneLenclud@433
   695
              MenuItem item = new MenuItem("Show in iMON FrontView");
StephaneLenclud@438
   696
              item.Checked = soundGraphDisplay.Contains(node.Sensor);
StephaneLenclud@433
   697
              item.Click += delegate(object obj, EventArgs args)
StephaneLenclud@433
   698
              {
StephaneLenclud@433
   699
                  if (item.Checked)
StephaneLenclud@433
   700
                      soundGraphDisplay.Remove(node.Sensor);
StephaneLenclud@433
   701
                  else
StephaneLenclud@433
   702
                      soundGraphDisplay.Add(node.Sensor, true);
StephaneLenclud@433
   703
              };
StephaneLenclud@433
   704
              treeContextMenu.MenuItems.Add(item);
StephaneLenclud@433
   705
          }
moel@211
   706
          if (gadget != null) {
moel@178
   707
            MenuItem item = new MenuItem("Show in Gadget");
moel@178
   708
            item.Checked = gadget.Contains(node.Sensor);
moel@178
   709
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   710
              if (item.Checked) {
moel@178
   711
                gadget.Remove(node.Sensor);
moel@178
   712
              } else {
moel@178
   713
                gadget.Add(node.Sensor);
moel@178
   714
              }
moel@178
   715
            };
moel@275
   716
            treeContextMenu.MenuItems.Add(item);
moel@178
   717
          }
moel@247
   718
          if (node.Sensor.Control != null) {
moel@275
   719
            treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@247
   720
            IControl control = node.Sensor.Control;
moel@247
   721
            MenuItem controlItem = new MenuItem("Control");
moel@247
   722
            MenuItem defaultItem = new MenuItem("Default");
moel@247
   723
            defaultItem.Checked = control.ControlMode == ControlMode.Default;
moel@247
   724
            controlItem.MenuItems.Add(defaultItem);
moel@247
   725
            defaultItem.Click += delegate(object obj, EventArgs args) {
moel@247
   726
              control.SetDefault();
moel@247
   727
            };
moel@275
   728
            MenuItem manualItem = new MenuItem("Manual");
moel@247
   729
            controlItem.MenuItems.Add(manualItem);
moel@247
   730
            manualItem.Checked = control.ControlMode == ControlMode.Software;
moel@247
   731
            for (int i = 0; i <= 100; i += 5) {
moel@247
   732
              if (i <= control.MaxSoftwareValue &&
moel@275
   733
                  i >= control.MinSoftwareValue) {
moel@247
   734
                MenuItem item = new MenuItem(i + " %");
moel@378
   735
                item.RadioCheck = true;
moel@247
   736
                manualItem.MenuItems.Add(item);
moel@247
   737
                item.Checked = control.ControlMode == ControlMode.Software &&
moel@247
   738
                  Math.Round(control.SoftwareValue) == i;
moel@247
   739
                int softwareValue = i;
moel@247
   740
                item.Click += delegate(object obj, EventArgs args) {
moel@247
   741
                  control.SetSoftware(softwareValue);
moel@247
   742
                };
moel@247
   743
              }
moel@247
   744
            }
moel@275
   745
            treeContextMenu.MenuItems.Add(controlItem);
moel@247
   746
          }
moel@176
   747
moel@275
   748
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@275
   749
        }
moel@275
   750
moel@275
   751
        HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
moel@275
   752
        if (hardwareNode != null && hardwareNode.Hardware != null) {
moel@275
   753
          treeContextMenu.MenuItems.Clear();
moel@275
   754
moel@275
   755
          if (nodeTextBoxText.EditEnabled) {
moel@275
   756
            MenuItem item = new MenuItem("Rename");
moel@275
   757
            item.Click += delegate(object obj, EventArgs args) {
moel@275
   758
              nodeTextBoxText.BeginEdit();
moel@275
   759
            };
moel@275
   760
            treeContextMenu.MenuItems.Add(item);
moel@275
   761
          }
moel@275
   762
moel@275
   763
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@40
   764
        }
moel@40
   765
      }
moel@1
   766
    }
moel@1
   767
moel@156
   768
    private void saveReportMenuItem_Click(object sender, EventArgs e) {
moel@83
   769
      string report = computer.GetReport();
moel@83
   770
      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
moel@83
   771
        using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
moel@83
   772
          w.Write(report);
moel@83
   773
        }
moel@83
   774
      }
moel@1
   775
    }
moel@1
   776
moel@82
   777
    private void SysTrayHideShow() {
moel@82
   778
      Visible = !Visible;
moel@82
   779
      if (Visible)
moel@82
   780
        Activate();    
moel@27
   781
    }
moel@27
   782
moel@27
   783
    protected override void WndProc(ref Message m) {
moel@27
   784
      const int WM_SYSCOMMAND = 0x112;
moel@27
   785
      const int SC_MINIMIZE = 0xF020;
paulwerelds@198
   786
      const int SC_CLOSE = 0xF060;
paulwerelds@198
   787
StephaneLenclud@436
   788
 
StephaneLenclud@436
   789
      if (minimizeToTray.Value &&
StephaneLenclud@435
   790
        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE)
StephaneLenclud@435
   791
      {
paulwerelds@198
   792
          SysTrayHideShow();
StephaneLenclud@435
   793
      }
StephaneLenclud@435
   794
      else if (minimizeOnClose.Value &&
StephaneLenclud@435
   795
      m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE)
StephaneLenclud@435
   796
      {
StephaneLenclud@435
   797
          /*
StephaneLenclud@435
   798
           * Apparently the user wants to minimize rather than close
StephaneLenclud@435
   799
           * Now we still need to check if we're going to the tray or not
StephaneLenclud@435
   800
           * 
StephaneLenclud@435
   801
           * Note: the correct way to do this would be to send out SC_MINIMIZE,
StephaneLenclud@435
   802
           * but since the code here is so simple,
StephaneLenclud@435
   803
           * that would just be a waste of time.
StephaneLenclud@435
   804
           */
StephaneLenclud@435
   805
          if (minimizeToTray.Value)
StephaneLenclud@435
   806
              SysTrayHideShow();
StephaneLenclud@435
   807
          else
StephaneLenclud@435
   808
              WindowState = FormWindowState.Minimized;
StephaneLenclud@435
   809
      }
StephaneLenclud@435
   810
      else
StephaneLenclud@435
   811
      {
StephaneLenclud@435
   812
          base.WndProc(ref m);
moel@27
   813
      }
moel@27
   814
    }
moel@27
   815
moel@82
   816
    private void hideShowClick(object sender, EventArgs e) {
moel@82
   817
      SysTrayHideShow();
moel@27
   818
    }
moel@27
   819
moel@63
   820
    private void ShowParameterForm(ISensor sensor) {
moel@63
   821
      ParameterForm form = new ParameterForm();
moel@63
   822
      form.Parameters = sensor.Parameters;
moel@63
   823
      form.captionLabel.Text = sensor.Name;
moel@63
   824
      form.ShowDialog();
moel@63
   825
    }
moel@63
   826
moel@63
   827
    private void treeView_NodeMouseDoubleClick(object sender, 
moel@63
   828
      TreeNodeAdvMouseEventArgs e) {
moel@63
   829
      SensorNode node = e.Node.Tag as SensorNode;
moel@63
   830
      if (node != null && node.Sensor != null && 
moel@63
   831
        node.Sensor.Parameters.Length > 0) {
moel@63
   832
        ShowParameterForm(node.Sensor);
moel@63
   833
      }
moel@63
   834
    }
moel@82
   835
moel@299
   836
    private void celsiusMenuItem_Click(object sender, EventArgs e) {
moel@299
   837
      celsiusMenuItem.Checked = true;
moel@156
   838
      fahrenheitMenuItem.Checked = false;
moel@299
   839
      unitManager.TemperatureUnit = TemperatureUnit.Celsius;
moel@122
   840
    }
moel@122
   841
moel@156
   842
    private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
moel@299
   843
      celsiusMenuItem.Checked = false;
moel@156
   844
      fahrenheitMenuItem.Checked = true;
moel@165
   845
      unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
moel@122
   846
    }
moel@150
   847
moel@156
   848
    private void sumbitReportMenuItem_Click(object sender, EventArgs e) 
moel@150
   849
    {
moel@150
   850
      ReportForm form = new ReportForm();
moel@150
   851
      form.Report = computer.GetReport();
moel@150
   852
      form.ShowDialog();      
moel@150
   853
    }
moel@151
   854
moel@151
   855
    private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
moel@159
   856
      computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
moel@159
   857
        sensor.ResetMin();
moel@159
   858
        sensor.ResetMax();
moel@159
   859
      }));
moel@151
   860
    }
moel@241
   861
moel@241
   862
    private void MainForm_MoveOrResize(object sender, EventArgs e) {
moel@241
   863
      if (WindowState != FormWindowState.Minimized) {
moel@241
   864
        settings.SetValue("mainForm.Location.X", Bounds.X);
moel@241
   865
        settings.SetValue("mainForm.Location.Y", Bounds.Y);
moel@241
   866
        settings.SetValue("mainForm.Width", Bounds.Width);
moel@241
   867
        settings.SetValue("mainForm.Height", Bounds.Height);
moel@241
   868
      }
moel@241
   869
    }
moel@262
   870
moel@262
   871
    private void resetClick(object sender, EventArgs e) {
moel@262
   872
      // disable the fallback MainIcon during reset, otherwise icon visibility
moel@262
   873
      // might be lost 
moel@262
   874
      systemTray.IsMainIconEnabled = false;
moel@262
   875
      computer.Close();
moel@262
   876
      computer.Open();
moel@262
   877
      // restore the MainIcon setting
moel@262
   878
      systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@262
   879
    }
moel@287
   880
moel@287
   881
    private void treeView_MouseMove(object sender, MouseEventArgs e) {
moel@288
   882
      selectionDragging = selectionDragging &
moel@288
   883
        (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0; 
moel@288
   884
moel@288
   885
      if (selectionDragging)
moel@288
   886
        treeView.SelectedNode = treeView.GetNodeAt(e.Location);     
moel@288
   887
    }
moel@288
   888
moel@288
   889
    private void treeView_MouseDown(object sender, MouseEventArgs e) {
moel@288
   890
      selectionDragging = true;
moel@288
   891
    }
moel@288
   892
moel@288
   893
    private void treeView_MouseUp(object sender, MouseEventArgs e) {
moel@288
   894
      selectionDragging = false;
moel@287
   895
    }
moel@348
   896
moel@348
   897
    private void serverPortMenuItem_Click(object sender, EventArgs e) {
moel@348
   898
      new PortForm(this).ShowDialog();
moel@348
   899
    }
moel@348
   900
moel@348
   901
    public HttpServer Server {
moel@348
   902
      get { return server; }
moel@348
   903
    }
moel@348
   904
moel@1
   905
  }
moel@1
   906
}