Browse Source

Fixed changes in the correct place.

BDisp 5 years ago
parent
commit
849a5dab18
2 changed files with 96 additions and 20 deletions
  1. 2 2
      Terminal.Gui/Core/Application.cs
  2. 94 18
      Terminal.Gui/Core/View.cs

+ 2 - 2
Terminal.Gui/Core/Application.cs

@@ -354,7 +354,7 @@ namespace Terminal.Gui {
 				if (OutsideFrame (new Point (nme.X, nme.Y), mouseGrabView.Frame))
 				if (OutsideFrame (new Point (nme.X, nme.Y), mouseGrabView.Frame))
 					lastMouseOwnerView.OnMouseLeave (me);
 					lastMouseOwnerView.OnMouseLeave (me);
 				if (mouseGrabView != null) {
 				if (mouseGrabView != null) {
-					mouseGrabView.MouseEvent (nme);
+					mouseGrabView.OnMouseEvent (nme);
 					return;
 					return;
 				}
 				}
 			}
 			}
@@ -387,7 +387,7 @@ namespace Terminal.Gui {
 					wantContinuousButtonPressedView = null;
 					wantContinuousButtonPressedView = null;
 
 
 				// Should we bubbled up the event, if it is not handled?
 				// Should we bubbled up the event, if it is not handled?
-				view.MouseEvent (nme);
+				view.OnMouseEvent (nme);
 			}
 			}
 		}
 		}
 
 

+ 94 - 18
Terminal.Gui/Core/View.cs

@@ -118,22 +118,27 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <summary>
 		/// Event fired when the view get focus.
 		/// Event fired when the view get focus.
 		/// </summary>
 		/// </summary>
-		public event EventHandler Enter;
+		public event EventHandler<FocusEventArgs> Enter;
 
 
 		/// <summary>
 		/// <summary>
 		/// Event fired when the view lost focus.
 		/// Event fired when the view lost focus.
 		/// </summary>
 		/// </summary>
-		public event EventHandler Leave;
+		public event EventHandler<FocusEventArgs> Leave;
 
 
 		/// <summary>
 		/// <summary>
 		/// Event fired when the view receives the mouse event for the first time.
 		/// Event fired when the view receives the mouse event for the first time.
 		/// </summary>
 		/// </summary>
-		public event EventHandler<MouseEvent> MouseEnter;
+		public event EventHandler<MouseEventEventArgs> MouseEnter;
 
 
 		/// <summary>
 		/// <summary>
 		/// Event fired when the view loses mouse event for the last time.
 		/// Event fired when the view loses mouse event for the last time.
 		/// </summary>
 		/// </summary>
-		public event EventHandler<MouseEvent> MouseLeave;
+		public event EventHandler<MouseEventEventArgs> MouseLeave;
+
+		/// <summary>
+		/// Event fired when a mouse event is generated.
+		/// </summary>
+		public event EventHandler<MouseEventEventArgs> MouseClick;
 
 
 		internal Direction FocusDirection {
 		internal Direction FocusDirection {
 			get => SuperView?.FocusDirection ?? focusDirection;
 			get => SuperView?.FocusDirection ?? focusDirection;
@@ -758,18 +763,45 @@ namespace Terminal.Gui {
 			}
 			}
 		}
 		}
 
 
+		/// <summary>
+		/// Specifies the event arguments for <see cref="SetFocus(View)"/>
+		/// </summary>
+		public class FocusEventArgs : EventArgs {
+			/// <summary>
+			/// Constructs.
+			/// </summary>
+			public FocusEventArgs () { }
+			/// <summary>
+			/// Indicates if the current focus event has already been processed and the driver should stop notifying any other event subscriber.
+			/// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
+			/// </summary>
+			public bool Handled { get; set; }
+		}
+
 		/// <inheritdoc cref="OnEnter"/>
 		/// <inheritdoc cref="OnEnter"/>
 		public override bool OnEnter ()
 		public override bool OnEnter ()
 		{
 		{
-			Enter?.Invoke (this, new EventArgs ());
-			return base.OnEnter ();
+			FocusEventArgs args = new FocusEventArgs ();
+			Enter?.Invoke (this, args);
+			if (args.Handled)
+				return true;
+			if (base.OnEnter ())
+				return true;
+
+			return false;
 		}
 		}
 
 
 		/// <inheritdoc cref="OnLeave"/>
 		/// <inheritdoc cref="OnLeave"/>
 		public override bool OnLeave ()
 		public override bool OnLeave ()
 		{
 		{
-			Leave?.Invoke (this, new EventArgs ());
-			return base.OnLeave ();
+			FocusEventArgs args = new FocusEventArgs ();
+			Leave?.Invoke (this, args);
+			if (args.Handled)
+				return true;
+			if (base.OnLeave ())
+				return true;
+
+			return false;
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>
@@ -1288,24 +1320,68 @@ namespace Terminal.Gui {
 			return $"{GetType ().Name}({Id})({Frame})";
 			return $"{GetType ().Name}({Id})({Frame})";
 		}
 		}
 
 
+		/// <summary>
+		/// Specifies the event arguments for <see cref="MouseEvent"/>
+		/// </summary>
+		public class MouseEventEventArgs : EventArgs {
+			/// <summary>
+			/// Constructs.
+			/// </summary>
+			/// <param name="me"></param>
+			public MouseEventEventArgs (MouseEvent me) => MouseEvent = me;
+			/// <summary>
+			/// The <see cref="MouseEvent"/> for the event.
+			/// </summary>
+			public MouseEvent MouseEvent { get; set; }
+			/// <summary>
+			/// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber.
+			/// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
+			/// </summary>
+			public bool Handled { get; set; }
+		}
+
 		/// <inheritdoc cref="OnMouseEnter(Gui.MouseEvent)"/>
 		/// <inheritdoc cref="OnMouseEnter(Gui.MouseEvent)"/>
 		public override bool OnMouseEnter (MouseEvent mouseEvent)
 		public override bool OnMouseEnter (MouseEvent mouseEvent)
 		{
 		{
-			if (!base.OnMouseEnter (mouseEvent)) {
-				MouseEnter?.Invoke (this, mouseEvent);
-				return false;
-			}
-			return true;
+			MouseEventEventArgs args = new MouseEventEventArgs (mouseEvent);
+			MouseEnter?.Invoke (this, args);
+			if (args.Handled)
+				return true;
+			if (base.OnMouseEnter (mouseEvent))
+				return true;
+
+			return false;
 		}
 		}
 
 
 		/// <inheritdoc cref="OnMouseLeave(Gui.MouseEvent)"/>
 		/// <inheritdoc cref="OnMouseLeave(Gui.MouseEvent)"/>
 		public override bool OnMouseLeave (MouseEvent mouseEvent)
 		public override bool OnMouseLeave (MouseEvent mouseEvent)
 		{
 		{
-			if (!base.OnMouseLeave (mouseEvent)) {
-				MouseLeave?.Invoke (this, mouseEvent);
-				return false;
-			}
-			return true;
+			MouseEventEventArgs args = new MouseEventEventArgs (mouseEvent);
+			MouseLeave?.Invoke (this, args);
+			if (args.Handled)
+				return true;
+			if (base.OnMouseLeave (mouseEvent))
+				return true;
+
+			return false;
+		}
+
+
+		/// <summary>
+		/// Method invoked when a mouse event is generated
+		/// </summary>
+		/// <param name="mouseEvent"></param>
+		/// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
+		public virtual bool OnMouseEvent (MouseEvent mouseEvent)
+		{
+			MouseEventEventArgs args = new MouseEventEventArgs (mouseEvent);
+			MouseClick?.Invoke (this, args);
+			if (args.Handled)
+				return true;
+			if (MouseEvent (mouseEvent))
+				return true;
+
+			return false;
 		}
 		}
 	}
 	}
 }
 }