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