using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Vanara.Windows.Forms.Annotations;
namespace Vanara.Windows.Forms
{
public class ButtonStateManager : IDisposable, INotifyPropertyChanged, IButtonControl
{
private PushButtonState currentState;
private Size oldSize;
private PushButtonState oldState;
/// Initializes a new instance of the BufferedPainter class.
///
/// Control this instance is attached to.
/// For best results, use a control which does not paint its background.
/// Note: Buffered painting does not work if the OptimizedDoubleBuffer newDS is set for the control.
///
public ButtonStateManager(Control control)
{
currentState = oldState = PushButtonState.Normal;
Control = control;
oldSize = Control.Size;
Control.EnabledChanged += Control_EnabledChanged;
Control.GotFocus += Control_GotFocus;
Control.LostFocus += Control_LostFocus;
Control.MouseDown += Control_MouseDown;
Control.MouseEnter += Control_MouseEnter;
Control.MouseLeave += Control_MouseLeave;
Control.MouseMove += Control_MouseMove;
Control.MouseUp += Control_MouseUp;
}
/// Gets the control this instance is attached to.
public Control Control { get; }
/// Gets or sets the current visual state.
public virtual PushButtonState State
{
get { return currentState; }
set
{
if (currentState == value) return;
oldState = currentState;
currentState = value;
Control.Invalidate();
}
}
/// Gets the last state of the button.
/// The last state of the button.
public virtual PushButtonState PriorButtonState => oldState;
public void Dispose()
{
if (Control == null) return;
Control.EnabledChanged -= Control_EnabledChanged;
Control.GotFocus -= Control_GotFocus;
Control.LostFocus -= Control_LostFocus;
Control.MouseDown -= Control_MouseDown;
Control.MouseEnter -= Control_MouseEnter;
Control.MouseLeave -= Control_MouseLeave;
Control.MouseMove -= Control_MouseMove;
Control.MouseUp -= Control_MouseUp;
}
private void Control_EnabledChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}
private void Control_GotFocus(object sender, EventArgs e) { throw new NotImplementedException(); }
private void Control_LostFocus(object sender, EventArgs eventArgs) { throw new NotImplementedException(); }
private void Control_MouseDown(object sender, MouseEventArgs mouseEventArgs) { throw new NotImplementedException(); }
private void Control_MouseEnter(object sender, EventArgs eventArgs) { throw new NotImplementedException(); }
private void Control_MouseLeave(object sender, EventArgs eventArgs) { throw new NotImplementedException(); }
private void Control_MouseMove(object sender, MouseEventArgs mouseEventArgs) { throw new NotImplementedException(); }
private void Control_MouseUp(object sender, MouseEventArgs mouseEventArgs) { throw new NotImplementedException(); }
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}