// // Core.cs: The core engine for gui.cs // // Authors: // Miguel de Icaza (miguel@gnome.org) // // Pending: // - Check for NeedDisplay on the hierarchy and repaint // - Layout support // - "Colors" type or "Attributes" type? // - What to surface as "BackgroundCOlor" when clearing a window, an attribute or colors? // // Optimziations // - Add rendering limitation to the exposed area using System.Reflection; namespace Terminal.Gui; /// Responder base class implemented by objects that want to participate on keyboard and mouse input. public class Responder : IDisposable { private bool disposedValue; /// Gets or sets a value indicating whether this can focus. /// true if can focus; otherwise, false. public virtual bool CanFocus { get; set; } /// Gets or sets a value indicating whether this can respond to user interaction. public virtual bool Enabled { get; set; } = true; /// Gets or sets a value indicating whether this has focus. /// true if has focus; otherwise, false. public virtual bool HasFocus { get; } /// Gets or sets a value indicating whether this and all its child controls are displayed. public virtual bool Visible { get; set; } = true; /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resource. public void Dispose () { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Disposing?.Invoke (this, EventArgs.Empty); Dispose (true); GC.SuppressFinalize (this); #if DEBUG_IDISPOSABLE WasDisposed = true; foreach (Responder instance in Instances.Where (x => x.WasDisposed).ToList ()) { Instances.Remove (instance); } #endif } /// Event raised when has been called to signal that this object is being disposed. public event EventHandler Disposing; /// Method invoked when a mouse event is generated /// true, if the event was handled, false otherwise. /// Contains the details about the mouse event. public virtual bool MouseEvent (MouseEvent mouseEvent) { return false; } /// Method invoked when the property from a view is changed. public virtual void OnCanFocusChanged () { } /// Method invoked when the property from a view is changed. public virtual void OnEnabledChanged () { } /// Method invoked when a view gets focus. /// The view that is losing focus. /// true, if the event was handled, false otherwise. public virtual bool OnEnter (View view) { return false; } /// Method invoked when a view loses focus. /// The view that is getting focus. /// true, if the event was handled, false otherwise. public virtual bool OnLeave (View view) { return false; } /// /// Called when the mouse first enters the view; the view will now receives mouse events until the mouse leaves /// the view. At which time, will be called. /// /// /// true, if the event was handled, false otherwise. public virtual bool OnMouseEnter (MouseEvent mouseEvent) { return false; } /// /// Called when the mouse has moved outside of the view; the view will no longer receive mouse events (until the /// mouse moves within the view again and is called). /// /// /// true, if the event was handled, false otherwise. public virtual bool OnMouseLeave (MouseEvent mouseEvent) { return false; } /// Method invoked when the property from a view is changed. public virtual void OnVisibleChanged () { } /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// /// If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and /// unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from /// inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed. /// /// protected virtual void Dispose (bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects) } disposedValue = true; } } // TODO: v2 - nuke this /// Utilty function to determine is overridden in the . /// The view. /// The method name. /// if it's overridden, otherwise. internal static bool IsOverridden (Responder subclass, string method) { MethodInfo m = subclass.GetType () .GetMethod ( method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly ); if (m == null) { return false; } return m.GetBaseDefinition ().DeclaringType != m.DeclaringType; } #if DEBUG_IDISPOSABLE /// For debug purposes to verify objects are being disposed properly public bool WasDisposed; /// For debug purposes to verify objects are being disposed properly public int DisposedCount = 0; /// For debug purposes public static List Instances = new (); /// For debug purposes public Responder () { Instances.Add (this); } #endif }