GUI/Gadget.cs
author moel.mich
Thu, 07 Jul 2011 20:41:09 +0000
changeset 308 d882720734bf
parent 289 d4798e7f4388
child 344 3145aadca3d2
permissions -rw-r--r--
Added support for reading the TAMG ACPI table on Gigabyte mainboards. Fixed a small problem with HDD/SSD names (0 chars are trimmed now as well).
moel@202
     1
/*
moel@176
     2
  
moel@176
     3
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
moel@176
     4
moel@176
     5
  The contents of this file are subject to the Mozilla Public License Version
moel@176
     6
  1.1 (the "License"); you may not use this file except in compliance with
moel@176
     7
  the License. You may obtain a copy of the License at
moel@176
     8
 
moel@176
     9
  http://www.mozilla.org/MPL/
moel@176
    10
moel@176
    11
  Software distributed under the License is distributed on an "AS IS" basis,
moel@176
    12
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
moel@176
    13
  for the specific language governing rights and limitations under the License.
moel@176
    14
moel@176
    15
  The Original Code is the Open Hardware Monitor code.
moel@176
    16
moel@176
    17
  The Initial Developer of the Original Code is 
moel@176
    18
  Michael Möller <m.moeller@gmx.ch>.
moel@302
    19
  Portions created by the Initial Developer are Copyright (C) 2010-2011
moel@176
    20
  the Initial Developer. All Rights Reserved.
moel@176
    21
moel@176
    22
  Contributor(s):
moel@176
    23
moel@176
    24
  Alternatively, the contents of this file may be used under the terms of
moel@176
    25
  either the GNU General Public License Version 2 or later (the "GPL"), or
moel@176
    26
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
moel@176
    27
  in which case the provisions of the GPL or the LGPL are applicable instead
moel@176
    28
  of those above. If you wish to allow use of your version of this file only
moel@176
    29
  under the terms of either the GPL or the LGPL, and not to allow others to
moel@176
    30
  use your version of this file under the terms of the MPL, indicate your
moel@176
    31
  decision by deleting the provisions above and replace them with the notice
moel@176
    32
  and other provisions required by the GPL or the LGPL. If you do not delete
moel@176
    33
  the provisions above, a recipient may use your version of this file under
moel@176
    34
  the terms of any one of the MPL, the GPL or the LGPL.
moel@176
    35
 
moel@176
    36
*/
moel@176
    37
moel@176
    38
using System;
moel@176
    39
using System.Drawing;
moel@176
    40
using System.Windows.Forms;
moel@176
    41
moel@176
    42
namespace OpenHardwareMonitor.GUI {
moel@176
    43
  public abstract class Gadget : IDisposable {
moel@176
    44
moel@176
    45
    private GadgetWindow window;
moel@176
    46
moel@176
    47
    public Gadget() {
moel@176
    48
      this.window = new GadgetWindow();
moel@302
    49
      this.window.Paint += delegate(object sender, PaintEventArgs e) {
moel@302
    50
        OnPaint(e);
moel@302
    51
      };
moel@176
    52
    }
moel@176
    53
moel@181
    54
    public virtual void Dispose() {
moel@302
    55
      window.Dispose();
moel@176
    56
    }
moel@176
    57
moel@176
    58
    public Point Location {
moel@176
    59
      get {
moel@176
    60
        return window.Location;
moel@176
    61
      }
moel@176
    62
      set {
moel@176
    63
        window.Location = value;
moel@176
    64
      }
moel@176
    65
    }
moel@176
    66
moel@176
    67
    public event EventHandler LocationChanged {
moel@176
    68
      add {
moel@176
    69
        window.LocationChanged += value;
moel@176
    70
      }
moel@176
    71
      remove {
moel@176
    72
        window.LocationChanged -= value;
moel@176
    73
      }
moel@176
    74
    }
moel@176
    75
moel@183
    76
    public virtual Size Size {
moel@176
    77
      get {
moel@176
    78
        return window.Size; 
moel@176
    79
      }
moel@183
    80
      set {        
moel@183
    81
        this.window.Size = value;
moel@183
    82
      }
moel@183
    83
    }
moel@183
    84
moel@183
    85
    public event EventHandler SizeChanged {
moel@183
    86
      add {
moel@183
    87
        window.SizeChanged += value;
moel@183
    88
      }
moel@183
    89
      remove {
moel@183
    90
        window.SizeChanged -= value;
moel@176
    91
      }
moel@176
    92
    }
moel@176
    93
moel@176
    94
    public byte Opacity {
moel@176
    95
      get {
moel@176
    96
        return window.Opacity;
moel@176
    97
      }
moel@176
    98
      set {
moel@176
    99
        window.Opacity = value;
moel@176
   100
      }
moel@176
   101
    }
moel@176
   102
moel@183
   103
    public bool LockPositionAndSize {
moel@176
   104
      get {
moel@183
   105
        return window.LockPositionAndSize;
moel@176
   106
      }
moel@176
   107
      set {
moel@183
   108
        window.LockPositionAndSize = value;
moel@176
   109
      }
moel@176
   110
    }
moel@176
   111
moel@176
   112
    public bool AlwaysOnTop {
moel@176
   113
      get {
moel@176
   114
        return window.AlwaysOnTop;
moel@176
   115
      }
moel@176
   116
      set {
moel@176
   117
        window.AlwaysOnTop = value;
moel@176
   118
      }
moel@176
   119
    }
moel@176
   120
moel@176
   121
    public ContextMenu ContextMenu {
moel@176
   122
      get {
moel@176
   123
        return window.ContextMenu;
moel@176
   124
      }
moel@176
   125
      set {
moel@176
   126
        window.ContextMenu = value;
moel@176
   127
      }
moel@176
   128
    }
moel@176
   129
moel@183
   130
    public event HitTestEventHandler HitTest {
moel@183
   131
      add {
moel@183
   132
        window.HitTest += value;
moel@183
   133
      }
moel@183
   134
      remove {
moel@183
   135
        window.HitTest -= value;
moel@183
   136
      }
moel@244
   137
    }
moel@244
   138
moel@244
   139
    public event MouseEventHandler MouseDoubleClick {
moel@244
   140
      add {
moel@244
   141
        window.MouseDoubleClick += value;
moel@244
   142
      }
moel@244
   143
      remove {
moel@244
   144
        window.MouseDoubleClick -= value;
moel@244
   145
      }
moel@244
   146
    }
moel@183
   147
moel@176
   148
    public bool Visible {
moel@176
   149
      get {
moel@176
   150
        return window.Visible;
moel@176
   151
      }
moel@176
   152
      set {
moel@176
   153
        if (value != window.Visible) {
moel@202
   154
          window.Visible = value;
moel@289
   155
          if (VisibleChanged != null)
moel@289
   156
            VisibleChanged(this, EventArgs.Empty);
moel@176
   157
          if (value)
moel@202
   158
            Redraw();          
moel@176
   159
        }
moel@176
   160
      }
moel@176
   161
    }
moel@176
   162
moel@289
   163
    public event EventHandler VisibleChanged;
moel@289
   164
moel@176
   165
    public void Redraw() {
moel@302
   166
      window.Redraw();
moel@176
   167
    }
moel@176
   168
moel@176
   169
    protected abstract void OnPaint(PaintEventArgs e);
moel@176
   170
  
moel@176
   171
  }
moel@176
   172
}