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