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