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