using System; using System.ComponentModel; using System.Runtime.InteropServices; using Decal.Interop.DHS; namespace Decal.Adapter.Wrappers; [CLSCompliant(true)] public class HotkeyWrapper : MarshalByRefObject, IDisposable { private Hotkey myHotkey; private bool isDisposed; [CLSCompliant(false)] [EditorBrowsable(EditorBrowsableState.Never)] public Hotkey Underlying => myHotkey; public bool AltState => myHotkey.AltState; public bool ControlState => myHotkey.ControlState; public bool ShiftState => myHotkey.ShiftState; public int VirtualKey => myHotkey.VirtualKey; public string Title => myHotkey.EventTitle; public string Description => myHotkey.EventDescription; internal HotkeyWrapper(Hotkey hotkey) { myHotkey = hotkey; } public HotkeyWrapper(string title, string description) : this(new HotkeyClass()) { myHotkey.EventTitle = title; myHotkey.EventDescription = description; } public HotkeyWrapper(string title, string description, int virtualKey, bool altState, bool controlState, bool shiftState) : this(title, description) { myHotkey.VirtualKey = virtualKey; myHotkey.AltState = altState; myHotkey.ControlState = controlState; myHotkey.ShiftState = shiftState; } ~HotkeyWrapper() { Dispose(disposing: false); } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!isDisposed) { } if (myHotkey != null) { Marshal.ReleaseComObject(myHotkey); } isDisposed = true; } protected void EnforceDisposedOnce() { if (isDisposed) { throw new ObjectDisposedException("HotkeyWrapper"); } } }