GUI/Gadget.cs
author moel.mich
Sun, 04 Aug 2013 06:54:46 +0000
changeset 419 07d44b20bbd4
parent 302 44c0e7f76e9e
permissions -rw-r--r--
Fixed an issue in the NCT677X class causing a crash when calling Update.
moel@202
     1
/*
moel@176
     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@176
     6
 
moel@344
     7
  Copyright (C) 2010-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@176
     9
*/
moel@176
    10
moel@176
    11
using System;
moel@176
    12
using System.Drawing;
moel@176
    13
using System.Windows.Forms;
moel@176
    14
moel@176
    15
namespace OpenHardwareMonitor.GUI {
moel@176
    16
  public abstract class Gadget : IDisposable {
moel@176
    17
moel@176
    18
    private GadgetWindow window;
moel@176
    19
moel@176
    20
    public Gadget() {
moel@176
    21
      this.window = new GadgetWindow();
moel@302
    22
      this.window.Paint += delegate(object sender, PaintEventArgs e) {
moel@302
    23
        OnPaint(e);
moel@302
    24
      };
moel@176
    25
    }
moel@176
    26
moel@181
    27
    public virtual void Dispose() {
moel@302
    28
      window.Dispose();
moel@176
    29
    }
moel@176
    30
moel@176
    31
    public Point Location {
moel@176
    32
      get {
moel@176
    33
        return window.Location;
moel@176
    34
      }
moel@176
    35
      set {
moel@176
    36
        window.Location = value;
moel@176
    37
      }
moel@176
    38
    }
moel@176
    39
moel@176
    40
    public event EventHandler LocationChanged {
moel@176
    41
      add {
moel@176
    42
        window.LocationChanged += value;
moel@176
    43
      }
moel@176
    44
      remove {
moel@176
    45
        window.LocationChanged -= value;
moel@176
    46
      }
moel@176
    47
    }
moel@176
    48
moel@183
    49
    public virtual Size Size {
moel@176
    50
      get {
moel@176
    51
        return window.Size; 
moel@176
    52
      }
moel@183
    53
      set {        
moel@183
    54
        this.window.Size = value;
moel@183
    55
      }
moel@183
    56
    }
moel@183
    57
moel@183
    58
    public event EventHandler SizeChanged {
moel@183
    59
      add {
moel@183
    60
        window.SizeChanged += value;
moel@183
    61
      }
moel@183
    62
      remove {
moel@183
    63
        window.SizeChanged -= value;
moel@176
    64
      }
moel@176
    65
    }
moel@176
    66
moel@176
    67
    public byte Opacity {
moel@176
    68
      get {
moel@176
    69
        return window.Opacity;
moel@176
    70
      }
moel@176
    71
      set {
moel@176
    72
        window.Opacity = value;
moel@176
    73
      }
moel@176
    74
    }
moel@176
    75
moel@183
    76
    public bool LockPositionAndSize {
moel@176
    77
      get {
moel@183
    78
        return window.LockPositionAndSize;
moel@176
    79
      }
moel@176
    80
      set {
moel@183
    81
        window.LockPositionAndSize = value;
moel@176
    82
      }
moel@176
    83
    }
moel@176
    84
moel@176
    85
    public bool AlwaysOnTop {
moel@176
    86
      get {
moel@176
    87
        return window.AlwaysOnTop;
moel@176
    88
      }
moel@176
    89
      set {
moel@176
    90
        window.AlwaysOnTop = value;
moel@176
    91
      }
moel@176
    92
    }
moel@176
    93
moel@176
    94
    public ContextMenu ContextMenu {
moel@176
    95
      get {
moel@176
    96
        return window.ContextMenu;
moel@176
    97
      }
moel@176
    98
      set {
moel@176
    99
        window.ContextMenu = value;
moel@176
   100
      }
moel@176
   101
    }
moel@176
   102
moel@183
   103
    public event HitTestEventHandler HitTest {
moel@183
   104
      add {
moel@183
   105
        window.HitTest += value;
moel@183
   106
      }
moel@183
   107
      remove {
moel@183
   108
        window.HitTest -= value;
moel@183
   109
      }
moel@244
   110
    }
moel@244
   111
moel@244
   112
    public event MouseEventHandler MouseDoubleClick {
moel@244
   113
      add {
moel@244
   114
        window.MouseDoubleClick += value;
moel@244
   115
      }
moel@244
   116
      remove {
moel@244
   117
        window.MouseDoubleClick -= value;
moel@244
   118
      }
moel@244
   119
    }
moel@183
   120
moel@176
   121
    public bool Visible {
moel@176
   122
      get {
moel@176
   123
        return window.Visible;
moel@176
   124
      }
moel@176
   125
      set {
moel@176
   126
        if (value != window.Visible) {
moel@202
   127
          window.Visible = value;
moel@289
   128
          if (VisibleChanged != null)
moel@289
   129
            VisibleChanged(this, EventArgs.Empty);
moel@176
   130
          if (value)
moel@202
   131
            Redraw();          
moel@176
   132
        }
moel@176
   133
      }
moel@176
   134
    }
moel@176
   135
moel@289
   136
    public event EventHandler VisibleChanged;
moel@289
   137
moel@176
   138
    public void Redraw() {
moel@302
   139
      window.Redraw();
moel@176
   140
    }
moel@176
   141
moel@176
   142
    protected abstract void OnPaint(PaintEventArgs e);
moel@176
   143
  
moel@176
   144
  }
moel@176
   145
}