GUI/Gadget.cs
author moel.mich
Thu, 26 Jul 2012 06:50:56 +0000
changeset 376 df64b56ece65
parent 302 44c0e7f76e9e
permissions -rw-r--r--
Fixed an error where loading config files from previous versions would crash the application.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2010-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Drawing;
    13 using System.Windows.Forms;
    14 
    15 namespace OpenHardwareMonitor.GUI {
    16   public abstract class Gadget : IDisposable {
    17 
    18     private GadgetWindow window;
    19 
    20     public Gadget() {
    21       this.window = new GadgetWindow();
    22       this.window.Paint += delegate(object sender, PaintEventArgs e) {
    23         OnPaint(e);
    24       };
    25     }
    26 
    27     public virtual void Dispose() {
    28       window.Dispose();
    29     }
    30 
    31     public Point Location {
    32       get {
    33         return window.Location;
    34       }
    35       set {
    36         window.Location = value;
    37       }
    38     }
    39 
    40     public event EventHandler LocationChanged {
    41       add {
    42         window.LocationChanged += value;
    43       }
    44       remove {
    45         window.LocationChanged -= value;
    46       }
    47     }
    48 
    49     public virtual Size Size {
    50       get {
    51         return window.Size; 
    52       }
    53       set {        
    54         this.window.Size = value;
    55       }
    56     }
    57 
    58     public event EventHandler SizeChanged {
    59       add {
    60         window.SizeChanged += value;
    61       }
    62       remove {
    63         window.SizeChanged -= value;
    64       }
    65     }
    66 
    67     public byte Opacity {
    68       get {
    69         return window.Opacity;
    70       }
    71       set {
    72         window.Opacity = value;
    73       }
    74     }
    75 
    76     public bool LockPositionAndSize {
    77       get {
    78         return window.LockPositionAndSize;
    79       }
    80       set {
    81         window.LockPositionAndSize = value;
    82       }
    83     }
    84 
    85     public bool AlwaysOnTop {
    86       get {
    87         return window.AlwaysOnTop;
    88       }
    89       set {
    90         window.AlwaysOnTop = value;
    91       }
    92     }
    93 
    94     public ContextMenu ContextMenu {
    95       get {
    96         return window.ContextMenu;
    97       }
    98       set {
    99         window.ContextMenu = value;
   100       }
   101     }
   102 
   103     public event HitTestEventHandler HitTest {
   104       add {
   105         window.HitTest += value;
   106       }
   107       remove {
   108         window.HitTest -= value;
   109       }
   110     }
   111 
   112     public event MouseEventHandler MouseDoubleClick {
   113       add {
   114         window.MouseDoubleClick += value;
   115       }
   116       remove {
   117         window.MouseDoubleClick -= value;
   118       }
   119     }
   120 
   121     public bool Visible {
   122       get {
   123         return window.Visible;
   124       }
   125       set {
   126         if (value != window.Visible) {
   127           window.Visible = value;
   128           if (VisibleChanged != null)
   129             VisibleChanged(this, EventArgs.Empty);
   130           if (value)
   131             Redraw();          
   132         }
   133       }
   134     }
   135 
   136     public event EventHandler VisibleChanged;
   137 
   138     public void Redraw() {
   139       window.Redraw();
   140     }
   141 
   142     protected abstract void OnPaint(PaintEventArgs e);
   143   
   144   }
   145 }