|
@@ -2,93 +2,77 @@
|
|
|
|
|
|
namespace Terminal.Gui;
|
|
|
|
|
|
-/// <summary>
|
|
|
-/// Describes the highlight style of a view.
|
|
|
-/// </summary>
|
|
|
-[Flags]
|
|
|
-public enum HighlightStyle
|
|
|
-{
|
|
|
- /// <summary>
|
|
|
- /// No highlight.
|
|
|
- /// </summary>
|
|
|
- None = 0,
|
|
|
-
|
|
|
-#if HOVER
|
|
|
- /// <summary>
|
|
|
- /// The mouse is hovering over the view.
|
|
|
- /// </summary>
|
|
|
- Hover = 1,
|
|
|
-#endif
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// The mouse is pressed within the <see cref="View.Viewport"/>.
|
|
|
- /// </summary>
|
|
|
- Pressed = 2,
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// The mouse is pressed but moved outside the <see cref="View.Viewport"/>.
|
|
|
- /// </summary>
|
|
|
- PressedOutside = 4
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary>
|
|
|
-/// Event arguments for the <see cref="View.Highlight"/> event.
|
|
|
-/// </summary>
|
|
|
-public class HighlightEventArgs : CancelEventArgs
|
|
|
+public partial class View
|
|
|
{
|
|
|
- /// <summary>
|
|
|
- /// Constructs a new instance of <see cref="HighlightEventArgs"/>.
|
|
|
- /// </summary>
|
|
|
- /// <param name="style"></param>
|
|
|
- public HighlightEventArgs (HighlightStyle style)
|
|
|
- {
|
|
|
- HighlightStyle = style;
|
|
|
- }
|
|
|
+ [CanBeNull]
|
|
|
+ private ColorScheme _savedHighlightColorScheme;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// The highlight style.
|
|
|
+ /// Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
|
|
|
+ /// to implement a custom highlight scheme or prevent the view from being highlighted.
|
|
|
/// </summary>
|
|
|
- public HighlightStyle HighlightStyle { get; }
|
|
|
-}
|
|
|
+ public event EventHandler<CancelEventArgs<HighlightStyle>> Highlight;
|
|
|
|
|
|
-public partial class View
|
|
|
-{
|
|
|
/// <summary>
|
|
|
/// Gets or sets whether the <see cref="View"/> will be highlighted visually while the mouse button is
|
|
|
/// pressed.
|
|
|
/// </summary>
|
|
|
public HighlightStyle HighlightStyle { get; set; }
|
|
|
|
|
|
- /// <summary>Gets or sets whether the <see cref="View"/> wants continuous button pressed events.</summary>
|
|
|
- public virtual bool WantContinuousButtonPressed { get; set; }
|
|
|
+ /// <summary>Event fired when a mouse click occurs.</summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// <para>
|
|
|
+ /// Fired when the mouse is either clicked or double-clicked. Check
|
|
|
+ /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
+ /// </para>
|
|
|
+ /// </remarks>
|
|
|
+ public event EventHandler<MouseEventEventArgs> MouseClick;
|
|
|
|
|
|
- /// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
|
|
|
- /// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
|
|
|
- public virtual bool WantMousePositionReports { get; set; }
|
|
|
+ /// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
|
|
|
+ public event EventHandler<MouseEventEventArgs> MouseEnter;
|
|
|
+
|
|
|
+ /// <summary>Event fired when a mouse event occurs.</summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// <para>
|
|
|
+ /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
+ /// </para>
|
|
|
+ /// </remarks>
|
|
|
+ public event EventHandler<MouseEventEventArgs> MouseEvent;
|
|
|
+
|
|
|
+ /// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
|
|
|
+ public event EventHandler<MouseEventEventArgs> MouseLeave;
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Called by <see cref="Application.OnMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
|
|
|
- /// then receive mouse events until <see cref="NewMouseLeaveEvent"/> is called indicating the mouse has left
|
|
|
- /// the view.
|
|
|
+ /// Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
|
|
|
+ /// event occurs.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
/// <para>
|
|
|
/// A view must be both enabled and visible to receive mouse events.
|
|
|
/// </para>
|
|
|
/// <para>
|
|
|
- /// This method calls <see cref="OnMouseEnter"/> to fire the event.
|
|
|
+ /// This method calls <see cref="OnMouseEvent"/> to process the event. If the event is not handled, and one of the
|
|
|
+ /// mouse buttons was clicked, it calls <see cref="OnMouseClick"/> to process the click.
|
|
|
/// </para>
|
|
|
/// <para>
|
|
|
/// See <see cref="SetHighlight"/> for more information.
|
|
|
/// </para>
|
|
|
+ /// <para>
|
|
|
+ /// If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, the <see cref="OnMouseClick"/> event
|
|
|
+ /// will be invoked repeatedly while the button is pressed.
|
|
|
+ /// </para>
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
/// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- internal bool? NewMouseEnterEvent (MouseEvent mouseEvent)
|
|
|
+ public bool? NewMouseEvent (MouseEvent mouseEvent)
|
|
|
{
|
|
|
if (!Enabled)
|
|
|
{
|
|
|
- return true;
|
|
|
+ // A disabled view should not eat mouse events
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
if (!CanBeVisible (this))
|
|
@@ -96,104 +80,112 @@ public partial class View
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (OnMouseEnter (mouseEvent) == true)
|
|
|
+ if (OnMouseEvent (mouseEvent))
|
|
|
{
|
|
|
- return true;
|
|
|
+ // Technically mouseEvent.Handled should already be true if implementers of OnMouseEvent
|
|
|
+ // follow the rules. But we'll update it just in case.
|
|
|
+ return mouseEvent.Handled = true;
|
|
|
}
|
|
|
|
|
|
-#if HOVER
|
|
|
- if (HighlightStyle.HasFlag(HighlightStyle.Hover))
|
|
|
+ if (HighlightStyle != HighlightStyle.None || WantContinuousButtonPressed)
|
|
|
{
|
|
|
- if (SetHighlight (HighlightStyle.Hover))
|
|
|
+ if (HandlePressed (mouseEvent))
|
|
|
{
|
|
|
- return true;
|
|
|
+ return mouseEvent.Handled;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (HandleReleased (mouseEvent))
|
|
|
+ {
|
|
|
+ return mouseEvent.Handled;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (HandleClicked (mouseEvent))
|
|
|
+ {
|
|
|
+ return mouseEvent.Handled;
|
|
|
}
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
+ if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button2DoubleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button1TripleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button2TripleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button3TripleClicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button4TripleClicked)
|
|
|
+ )
|
|
|
+ {
|
|
|
+ // If it's a click, and we didn't handle it, then we'll call OnMouseClick
|
|
|
+ // We get here if the view did not handle the mouse event via OnMouseEvent/MouseEvent and
|
|
|
+ // it did not handle the press/release/clicked events via HandlePress/HandleRelease/HandleClicked
|
|
|
+ return OnMouseClick (new (mouseEvent));
|
|
|
+ }
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>Gets or sets whether the <see cref="View"/> wants continuous button pressed events.</summary>
|
|
|
+ public virtual bool WantContinuousButtonPressed { get; set; }
|
|
|
+
|
|
|
+ /// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
|
|
|
+ /// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
|
|
|
+ public virtual bool WantMousePositionReports { get; set; }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Called by <see cref="NewMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
|
|
|
/// then receive mouse events until <see cref="OnMouseLeave"/> is called indicating the mouse has left
|
|
|
/// the view.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// <para>
|
|
|
- /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default enter behavior.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
- /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default enter behavior.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
+ /// </para>
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
protected internal virtual bool? OnMouseEnter (MouseEvent mouseEvent)
|
|
|
{
|
|
|
-
|
|
|
var args = new MouseEventEventArgs (mouseEvent);
|
|
|
MouseEnter?.Invoke (this, args);
|
|
|
|
|
|
return args.Handled;
|
|
|
}
|
|
|
|
|
|
- /// <summary>Event fired when the mouse moves into the View's <see cref="Viewport"/>.</summary>
|
|
|
- public event EventHandler<MouseEventEventArgs> MouseEnter;
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Called by <see cref="Application.OnMouseEvent"/> when the mouse leaves <see cref="Viewport"/>. The view will
|
|
|
- /// then no longer receive mouse events.
|
|
|
- /// </summary>
|
|
|
+ /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
|
|
|
/// <remarks>
|
|
|
/// <para>
|
|
|
- /// A view must be both enabled and visible to receive mouse events.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// This method calls <see cref="OnMouseLeave"/> to fire the event.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// See <see cref="SetHighlight"/> for more information.
|
|
|
+ /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
/// </para>
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
- /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent)
|
|
|
+ /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
+ protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent)
|
|
|
{
|
|
|
- if (!Enabled)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- if (!CanBeVisible (this))
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ var args = new MouseEventEventArgs (mouseEvent);
|
|
|
|
|
|
- if (OnMouseLeave (mouseEvent) == true)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-#if HOVER
|
|
|
- if (HighlightStyle.HasFlag (HighlightStyle.Hover))
|
|
|
- {
|
|
|
- SetHighlight (HighlightStyle.None);
|
|
|
- }
|
|
|
-#endif
|
|
|
+ MouseEvent?.Invoke (this, args);
|
|
|
|
|
|
- return false;
|
|
|
+ return args.Handled;
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Called by <see cref="NewMouseEvent"/> when a mouse leaves <see cref="Viewport"/>. The view will
|
|
|
/// no longer receive mouse events.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// <para>
|
|
|
- /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default leave behavior.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
- /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// Override this method or subscribe to <see cref="MouseEnter"/> to change the default leave behavior.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
+ /// </para>
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
@@ -215,143 +207,90 @@ public partial class View
|
|
|
return args.Handled;
|
|
|
}
|
|
|
|
|
|
- /// <summary>Event fired when the mouse leaves the View's <see cref="Viewport"/>.</summary>
|
|
|
- public event EventHandler<MouseEventEventArgs> MouseLeave;
|
|
|
-
|
|
|
/// <summary>
|
|
|
- /// Processes a <see cref="MouseEvent"/>. This method is called by <see cref="Application.OnMouseEvent"/> when a mouse
|
|
|
- /// event occurs.
|
|
|
+ /// Called when the view is to be highlighted.
|
|
|
/// </summary>
|
|
|
+ /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
+ protected virtual bool? OnHighlight (CancelEventArgs<HighlightStyle> args)
|
|
|
+ {
|
|
|
+ Highlight?.Invoke (this, args);
|
|
|
+
|
|
|
+ if (args.Cancel)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Margin?.Highlight?.Invoke (this, args);
|
|
|
+
|
|
|
+ //args = new (highlight);
|
|
|
+ //Border?.Highlight?.Invoke (this, args);
|
|
|
+
|
|
|
+ //args = new (highlight);
|
|
|
+ //Padding?.Highlight?.Invoke (this, args);
|
|
|
+
|
|
|
+ return args.Cancel;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>Invokes the MouseClick event.</summary>
|
|
|
/// <remarks>
|
|
|
/// <para>
|
|
|
- /// A view must be both enabled and visible to receive mouse events.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// This method calls <see cref="OnMouseEvent"/> to process the event. If the event is not handled, and one of the
|
|
|
- /// mouse buttons was clicked, it calls <see cref="OnMouseClick"/> to process the click.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// See <see cref="SetHighlight"/> for more information.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, the <see cref="OnMouseClick"/> event
|
|
|
- /// will be invoked repeatedly while the button is pressed.
|
|
|
+ /// Called when the mouse is either clicked or double-clicked. Check
|
|
|
+ /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
|
|
|
/// </para>
|
|
|
/// </remarks>
|
|
|
- /// <param name="mouseEvent"></param>
|
|
|
- /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- public bool? NewMouseEvent (MouseEvent mouseEvent)
|
|
|
+ /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
+ protected bool OnMouseClick (MouseEventEventArgs args)
|
|
|
{
|
|
|
if (!Enabled)
|
|
|
{
|
|
|
- // A disabled view should not eat mouse events
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!CanBeVisible (this))
|
|
|
- {
|
|
|
- return false;
|
|
|
+ // QUESTION: Is this right? Should a disabled view eat mouse clicks?
|
|
|
+ return args.Handled = true;
|
|
|
}
|
|
|
|
|
|
- if (OnMouseEvent (mouseEvent))
|
|
|
- {
|
|
|
- // Technically mouseEvent.Handled should already be true if implementers of OnMouseEvent
|
|
|
- // follow the rules. But we'll update it just in case.
|
|
|
- return mouseEvent.Handled = true;
|
|
|
- }
|
|
|
+ MouseClick?.Invoke (this, args);
|
|
|
|
|
|
- if (HighlightStyle != Gui.HighlightStyle.None || WantContinuousButtonPressed)
|
|
|
+ if (args.Handled)
|
|
|
{
|
|
|
- if (HandlePressed (mouseEvent))
|
|
|
- {
|
|
|
- return mouseEvent.Handled;
|
|
|
- }
|
|
|
-
|
|
|
- if (HandleReleased (mouseEvent))
|
|
|
- {
|
|
|
- return mouseEvent.Handled;
|
|
|
- }
|
|
|
-
|
|
|
- if (HandleClicked (mouseEvent))
|
|
|
- {
|
|
|
- return mouseEvent.Handled;
|
|
|
- }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button2DoubleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button3DoubleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button4DoubleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button1TripleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button2TripleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button3TripleClicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button4TripleClicked)
|
|
|
- )
|
|
|
+ if (!HasFocus && CanFocus)
|
|
|
{
|
|
|
- // If it's a click, and we didn't handle it, then we'll call OnMouseClick
|
|
|
- // We get here if the view did not handle the mouse event via OnMouseEvent/MouseEvent and
|
|
|
- // it did not handle the press/release/clicked events via HandlePress/HandleRelease/HandleClicked
|
|
|
- return OnMouseClick (new (mouseEvent));
|
|
|
+ args.Handled = true;
|
|
|
+ SetFocus ();
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
+ return args.Handled;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
|
|
|
+ /// For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
|
|
|
/// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// <para>
|
|
|
- /// Marked internal just to support unit tests
|
|
|
- /// </para>
|
|
|
+ /// Marked internal just to support unit tests
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- private bool HandlePressed (MouseEvent mouseEvent)
|
|
|
+ /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
+ internal bool HandleClicked (MouseEvent mouseEvent)
|
|
|
{
|
|
|
- if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
|
|
|
+ if (Application.MouseGrabView == this
|
|
|
+ && (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)))
|
|
|
{
|
|
|
- // The first time we get pressed event, grab the mouse and set focus
|
|
|
- if (Application.MouseGrabView != this)
|
|
|
- {
|
|
|
- Application.GrabMouse (this);
|
|
|
-
|
|
|
- if (!HasFocus && CanFocus)
|
|
|
- {
|
|
|
- // Set the focus, but don't invoke Accept
|
|
|
- SetFocus ();
|
|
|
- }
|
|
|
-
|
|
|
- mouseEvent.Handled = true;
|
|
|
- }
|
|
|
+ // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
|
|
|
+ Application.UngrabMouse ();
|
|
|
|
|
|
- if (Viewport.Contains (mouseEvent.Position))
|
|
|
- {
|
|
|
- if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None) == true)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ if (SetHighlight (HighlightStyle.None))
|
|
|
{
|
|
|
- if (this is not Adornment && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None) == true)
|
|
|
-
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- if (WantContinuousButtonPressed && Application.MouseGrabView == this)
|
|
|
+ // If mouse is still in bounds, click
|
|
|
+ if (!WantContinuousButtonPressed && Viewport.Contains (mouseEvent.Position))
|
|
|
{
|
|
|
- // If this is not the first pressed event, click
|
|
|
return OnMouseClick (new (mouseEvent));
|
|
|
}
|
|
|
|
|
@@ -389,45 +328,95 @@ public partial class View
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
|
|
|
- /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
|
|
|
+ /// Called by <see cref="Application.OnMouseEvent"/> when the mouse enters <see cref="Viewport"/>. The view will
|
|
|
+ /// then receive mouse events until <see cref="NewMouseLeaveEvent"/> is called indicating the mouse has left
|
|
|
+ /// the view.
|
|
|
/// </summary>
|
|
|
/// <remarks>
|
|
|
- /// Marked internal just to support unit tests
|
|
|
+ /// <para>
|
|
|
+ /// A view must be both enabled and visible to receive mouse events.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// This method calls <see cref="OnMouseEnter"/> to fire the event.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// See <see cref="SetHighlight"/> for more information.
|
|
|
+ /// </para>
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- internal bool HandleClicked (MouseEvent mouseEvent)
|
|
|
+ /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
+ internal bool? NewMouseEnterEvent (MouseEvent mouseEvent)
|
|
|
{
|
|
|
- if (Application.MouseGrabView == this
|
|
|
- && (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
|
|
|
- || mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)))
|
|
|
+ if (!Enabled)
|
|
|
{
|
|
|
- // We're grabbed. Clicked event comes after the last Release. This is our signal to ungrab
|
|
|
- Application.UngrabMouse ();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- if (SetHighlight (HighlightStyle.None))
|
|
|
+ if (!CanBeVisible (this))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OnMouseEnter (mouseEvent) == true)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+#if HOVER
|
|
|
+ if (HighlightStyle.HasFlag(HighlightStyle.Hover))
|
|
|
+ {
|
|
|
+ if (SetHighlight (HighlightStyle.Hover))
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // If mouse is still in bounds, click
|
|
|
- if (!WantContinuousButtonPressed && Viewport.Contains (mouseEvent.Position))
|
|
|
- {
|
|
|
- return OnMouseClick (new (mouseEvent));
|
|
|
- }
|
|
|
+ /// <summary>
|
|
|
+ /// Called by <see cref="Application.OnMouseEvent"/> when the mouse leaves <see cref="Viewport"/>. The view will
|
|
|
+ /// then no longer receive mouse events.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// <para>
|
|
|
+ /// A view must be both enabled and visible to receive mouse events.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// This method calls <see cref="OnMouseLeave"/> to fire the event.
|
|
|
+ /// </para>
|
|
|
+ /// <para>
|
|
|
+ /// See <see cref="SetHighlight"/> for more information.
|
|
|
+ /// </para>
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="mouseEvent"></param>
|
|
|
+ /// <returns><see langword="true"/> if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
+ internal bool? NewMouseLeaveEvent (MouseEvent mouseEvent)
|
|
|
+ {
|
|
|
+ if (!Enabled)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- return mouseEvent.Handled = true;
|
|
|
+ if (!CanBeVisible (this))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OnMouseLeave (mouseEvent))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+#if HOVER
|
|
|
+ if (HighlightStyle.HasFlag (HighlightStyle.Hover))
|
|
|
+ {
|
|
|
+ SetHighlight (HighlightStyle.None);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- [CanBeNull]
|
|
|
- private ColorScheme _savedHighlightColorScheme;
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Enables the highlight for the view when the mouse is pressed. Called from OnMouseEvent.
|
|
|
/// </summary>
|
|
@@ -443,8 +432,7 @@ public partial class View
|
|
|
/// </para>
|
|
|
/// </remarks>
|
|
|
/// <returns><see langword="true"/>, if the Highlight event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
-
|
|
|
- internal bool SetHighlight (HighlightStyle style)
|
|
|
+ internal bool SetHighlight (HighlightStyle newHighlightStyle)
|
|
|
{
|
|
|
// TODO: Make the highlight colors configurable
|
|
|
if (!CanFocus)
|
|
@@ -453,7 +441,10 @@ public partial class View
|
|
|
}
|
|
|
|
|
|
// Enable override via virtual method and/or event
|
|
|
- if (OnHighlight (style) == true)
|
|
|
+ HighlightStyle copy = HighlightStyle;
|
|
|
+ var args = new CancelEventArgs<HighlightStyle> (ref copy, ref newHighlightStyle);
|
|
|
+
|
|
|
+ if (OnHighlight (args) == true)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
@@ -474,8 +465,8 @@ public partial class View
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
-#endif
|
|
|
- if (style.HasFlag (HighlightStyle.Pressed) || style.HasFlag (HighlightStyle.PressedOutside))
|
|
|
+#endif
|
|
|
+ if (args.NewValue.HasFlag (HighlightStyle.Pressed) || args.NewValue.HasFlag (HighlightStyle.PressedOutside))
|
|
|
{
|
|
|
if (_savedHighlightColorScheme is null && ColorScheme is { })
|
|
|
{
|
|
@@ -486,7 +477,7 @@ public partial class View
|
|
|
var cs = new ColorScheme (ColorScheme)
|
|
|
{
|
|
|
// Highlight the foreground focus color
|
|
|
- Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ()),
|
|
|
+ Focus = new (ColorScheme.Focus.Foreground.GetHighlightColor (), ColorScheme.Focus.Background.GetHighlightColor ())
|
|
|
};
|
|
|
ColorScheme = cs;
|
|
|
}
|
|
@@ -500,12 +491,12 @@ public partial class View
|
|
|
ColorScheme = cs;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// Return false since we don't want to eat the event
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (style == HighlightStyle.None)
|
|
|
+ if (args.NewValue == HighlightStyle.None)
|
|
|
{
|
|
|
// Unhighlight
|
|
|
if (_savedHighlightColorScheme is { })
|
|
@@ -519,103 +510,64 @@ public partial class View
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Fired when the view is highlighted. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/>
|
|
|
- /// to implement a custom highlight scheme or prevent the view from being highlighted.
|
|
|
- /// </summary>
|
|
|
- public event EventHandler<HighlightEventArgs> Highlight;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Called when the view is to be highlighted.
|
|
|
+ /// For cases where the view is grabbed and the mouse is clicked, this method handles the released event (typically
|
|
|
+ /// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
|
|
|
/// </summary>
|
|
|
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- protected virtual bool? OnHighlight (HighlightStyle highlight)
|
|
|
- {
|
|
|
- HighlightEventArgs args = new (highlight);
|
|
|
- Highlight?.Invoke (this, args);
|
|
|
-
|
|
|
- if (args.Cancel)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- args = new (highlight);
|
|
|
- Margin?.Highlight?.Invoke (this, args);
|
|
|
-
|
|
|
- //args = new (highlight);
|
|
|
- //Border?.Highlight?.Invoke (this, args);
|
|
|
-
|
|
|
- //args = new (highlight);
|
|
|
- //Padding?.Highlight?.Invoke (this, args);
|
|
|
-
|
|
|
- return args.Cancel;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>Called when a mouse event occurs within the view's <see cref="Viewport"/>.</summary>
|
|
|
/// <remarks>
|
|
|
/// <para>
|
|
|
- /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
+ /// Marked internal just to support unit tests
|
|
|
/// </para>
|
|
|
/// </remarks>
|
|
|
/// <param name="mouseEvent"></param>
|
|
|
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent)
|
|
|
+ private bool HandlePressed (MouseEvent mouseEvent)
|
|
|
{
|
|
|
- var args = new MouseEventEventArgs (mouseEvent);
|
|
|
-
|
|
|
- MouseEvent?.Invoke (this, args);
|
|
|
+ if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
|
|
|
+ || mouseEvent.Flags.HasFlag (MouseFlags.Button4Pressed))
|
|
|
+ {
|
|
|
+ // The first time we get pressed event, grab the mouse and set focus
|
|
|
+ if (Application.MouseGrabView != this)
|
|
|
+ {
|
|
|
+ Application.GrabMouse (this);
|
|
|
|
|
|
- return args.Handled;
|
|
|
- }
|
|
|
+ if (!HasFocus && CanFocus)
|
|
|
+ {
|
|
|
+ // Set the focus, but don't invoke Accept
|
|
|
+ SetFocus ();
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>Event fired when a mouse event occurs.</summary>
|
|
|
- /// <remarks>
|
|
|
- /// <para>
|
|
|
- /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
- /// </para>
|
|
|
- /// </remarks>
|
|
|
- public event EventHandler<MouseEventEventArgs> MouseEvent;
|
|
|
+ mouseEvent.Handled = true;
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>Invokes the MouseClick event.</summary>
|
|
|
- /// <remarks>
|
|
|
- /// <para>
|
|
|
- /// Called when the mouse is either clicked or double-clicked. Check
|
|
|
- /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
|
|
|
- /// </para>
|
|
|
- /// </remarks>
|
|
|
- /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
|
|
- protected bool OnMouseClick (MouseEventEventArgs args)
|
|
|
- {
|
|
|
- if (!Enabled)
|
|
|
- {
|
|
|
- // QUESTION: Is this right? Should a disabled view eat mouse clicks?
|
|
|
- return args.Handled = true;
|
|
|
- }
|
|
|
+ if (Viewport.Contains (mouseEvent.Position))
|
|
|
+ {
|
|
|
+ if (this is not Adornment
|
|
|
+ && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.Pressed) ? HighlightStyle.Pressed : HighlightStyle.None))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (this is not Adornment
|
|
|
+ && SetHighlight (HighlightStyle.HasFlag (HighlightStyle.PressedOutside) ? HighlightStyle.PressedOutside : HighlightStyle.None))
|
|
|
|
|
|
- MouseClick?.Invoke (this, args);
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (args.Handled)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if (WantContinuousButtonPressed && Application.MouseGrabView == this)
|
|
|
+ {
|
|
|
+ // If this is not the first pressed event, click
|
|
|
+ return OnMouseClick (new (mouseEvent));
|
|
|
+ }
|
|
|
|
|
|
- if (!HasFocus && CanFocus)
|
|
|
- {
|
|
|
- args.Handled = true;
|
|
|
- SetFocus ();
|
|
|
+ return mouseEvent.Handled = true;
|
|
|
}
|
|
|
|
|
|
- return args.Handled;
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- /// <summary>Event fired when a mouse click occurs.</summary>
|
|
|
- /// <remarks>
|
|
|
- /// <para>
|
|
|
- /// Fired when the mouse is either clicked or double-clicked. Check
|
|
|
- /// <see cref="MouseEvent.Flags"/> to see which button was clicked.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// The coordinates are relative to <see cref="View.Viewport"/>.
|
|
|
- /// </para>
|
|
|
- /// </remarks>
|
|
|
- public event EventHandler<MouseEventEventArgs> MouseClick;
|
|
|
}
|