moel@202: /* moel@176: moel@344: This Source Code Form is subject to the terms of the Mozilla Public moel@344: License, v. 2.0. If a copy of the MPL was not distributed with this moel@344: file, You can obtain one at http://mozilla.org/MPL/2.0/. moel@176: moel@344: Copyright (C) 2010-2011 Michael Möller moel@344: moel@176: */ moel@176: moel@176: using System; moel@176: using System.Drawing; moel@176: using System.Windows.Forms; moel@176: moel@176: namespace OpenHardwareMonitor.GUI { moel@176: public abstract class Gadget : IDisposable { moel@176: moel@176: private GadgetWindow window; moel@176: moel@176: public Gadget() { moel@176: this.window = new GadgetWindow(); moel@302: this.window.Paint += delegate(object sender, PaintEventArgs e) { moel@302: OnPaint(e); moel@302: }; moel@176: } moel@176: moel@181: public virtual void Dispose() { moel@302: window.Dispose(); moel@176: } moel@176: moel@176: public Point Location { moel@176: get { moel@176: return window.Location; moel@176: } moel@176: set { moel@176: window.Location = value; moel@176: } moel@176: } moel@176: moel@176: public event EventHandler LocationChanged { moel@176: add { moel@176: window.LocationChanged += value; moel@176: } moel@176: remove { moel@176: window.LocationChanged -= value; moel@176: } moel@176: } moel@176: moel@183: public virtual Size Size { moel@176: get { moel@176: return window.Size; moel@176: } moel@183: set { moel@183: this.window.Size = value; moel@183: } moel@183: } moel@183: moel@183: public event EventHandler SizeChanged { moel@183: add { moel@183: window.SizeChanged += value; moel@183: } moel@183: remove { moel@183: window.SizeChanged -= value; moel@176: } moel@176: } moel@176: moel@176: public byte Opacity { moel@176: get { moel@176: return window.Opacity; moel@176: } moel@176: set { moel@176: window.Opacity = value; moel@176: } moel@176: } moel@176: moel@183: public bool LockPositionAndSize { moel@176: get { moel@183: return window.LockPositionAndSize; moel@176: } moel@176: set { moel@183: window.LockPositionAndSize = value; moel@176: } moel@176: } moel@176: moel@176: public bool AlwaysOnTop { moel@176: get { moel@176: return window.AlwaysOnTop; moel@176: } moel@176: set { moel@176: window.AlwaysOnTop = value; moel@176: } moel@176: } moel@176: moel@176: public ContextMenu ContextMenu { moel@176: get { moel@176: return window.ContextMenu; moel@176: } moel@176: set { moel@176: window.ContextMenu = value; moel@176: } moel@176: } moel@176: moel@183: public event HitTestEventHandler HitTest { moel@183: add { moel@183: window.HitTest += value; moel@183: } moel@183: remove { moel@183: window.HitTest -= value; moel@183: } moel@244: } moel@244: moel@244: public event MouseEventHandler MouseDoubleClick { moel@244: add { moel@244: window.MouseDoubleClick += value; moel@244: } moel@244: remove { moel@244: window.MouseDoubleClick -= value; moel@244: } moel@244: } moel@183: moel@176: public bool Visible { moel@176: get { moel@176: return window.Visible; moel@176: } moel@176: set { moel@176: if (value != window.Visible) { moel@202: window.Visible = value; moel@289: if (VisibleChanged != null) moel@289: VisibleChanged(this, EventArgs.Empty); moel@176: if (value) moel@202: Redraw(); moel@176: } moel@176: } moel@176: } moel@176: moel@289: public event EventHandler VisibleChanged; moel@289: moel@176: public void Redraw() { moel@302: window.Redraw(); moel@176: } moel@176: moel@176: protected abstract void OnPaint(PaintEventArgs e); moel@176: moel@176: } moel@176: }