浏览代码

Fix mouse issue in a modal view.

BDisp 2 年之前
父节点
当前提交
1badf8a585
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 0 2
      Terminal.Gui/Core/Application.cs
  2. 18 0
      Terminal.Gui/Views/Menu.cs

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

@@ -809,8 +809,6 @@ namespace Terminal.Gui {
 			}
 			}
 
 
 			if (mouseGrabView != null) {
 			if (mouseGrabView != null) {
-				view ??= mouseGrabView;
-
 				var newxy = mouseGrabView.ScreenToView (me.X, me.Y);
 				var newxy = mouseGrabView.ScreenToView (me.X, me.Y);
 				var nme = new MouseEvent () {
 				var nme = new MouseEvent () {
 					X = newxy.X,
 					X = newxy.X,

+ 18 - 0
Terminal.Gui/Views/Menu.cs

@@ -480,6 +480,7 @@ namespace Terminal.Gui {
 			if (Application.Current != null) {
 			if (Application.Current != null) {
 				Application.Current.DrawContentComplete += Current_DrawContentComplete;
 				Application.Current.DrawContentComplete += Current_DrawContentComplete;
 			}
 			}
+			Application.RootMouseEvent += Application_RootMouseEvent;
 
 
 			// Things this view knows how to do
 			// Things this view knows how to do
 			AddCommand (Command.LineUp, () => MoveUp ());
 			AddCommand (Command.LineUp, () => MoveUp ());
@@ -506,6 +507,22 @@ namespace Terminal.Gui {
 			AddKeyBinding (Key.Enter, Command.Accept);
 			AddKeyBinding (Key.Enter, Command.Accept);
 		}
 		}
 
 
+		private void Application_RootMouseEvent (MouseEvent me)
+		{
+			var view = View.FindDeepestView (this, me.X, me.Y, out int rx, out int ry);
+			if (view == this) {
+				var nme = new MouseEvent () {
+					X = rx,
+					Y = ry,
+					Flags = me.Flags,
+					View = view
+				};
+				if (MouseEvent (nme) || me.Flags == MouseFlags.Button1Pressed || me.Flags == MouseFlags.Button1Released) {
+					me.Handled = true;
+				}
+			}
+		}
+
 		internal Attribute DetermineColorSchemeFor (MenuItem item, int index)
 		internal Attribute DetermineColorSchemeFor (MenuItem item, int index)
 		{
 		{
 			if (item != null) {
 			if (item != null) {
@@ -922,6 +939,7 @@ namespace Terminal.Gui {
 			if (Application.Current != null) {
 			if (Application.Current != null) {
 				Application.Current.DrawContentComplete -= Current_DrawContentComplete;
 				Application.Current.DrawContentComplete -= Current_DrawContentComplete;
 			}
 			}
+			Application.RootMouseEvent -= Application_RootMouseEvent;
 			base.Dispose (disposing);
 			base.Dispose (disposing);
 		}
 		}
 	}
 	}