浏览代码

Fixes menu frame and unit test on the #2483. (#2542)

* Fixes menu frame and unit test on the #2483.

* Reverting some code. Only color on ScrollView is failing.

* Fixes for the unit test Draw_A_ContextManu_Over_A_Dialog pass.
BDisp 2 年之前
父节点
当前提交
5ae8e98631

+ 2 - 2
Terminal.Gui/View/Frame.cs

@@ -148,8 +148,8 @@ namespace Terminal.Gui {
 			var borderBounds = new Rect (
 			var borderBounds = new Rect (
 				screenBounds.X + Math.Max (0, Thickness.Left - 1),
 				screenBounds.X + Math.Max (0, Thickness.Left - 1),
 				screenBounds.Y + Math.Max (0, Thickness.Top - 1),
 				screenBounds.Y + Math.Max (0, Thickness.Top - 1),
-				screenBounds.Width - Math.Max (0, Math.Max (0, Thickness.Left - 1) - Math.Max (0, Thickness.Right - 1)),
-				screenBounds.Height - Math.Max (0, Math.Max (0, Thickness.Top - 1) - Math.Max (0, Thickness.Bottom - 1)));
+				Math.Max (0, screenBounds.Width - Math.Max (0, Math.Max (0, Thickness.Left - 1) + Math.Max (0, Thickness.Right - 1))),
+				Math.Max (0, screenBounds.Height - Math.Max (0, Math.Max (0, Thickness.Top - 1) + Math.Max (0, Thickness.Bottom - 1))));
 
 
 			var topTitleLineY = borderBounds.Y;
 			var topTitleLineY = borderBounds.Y;
 			var titleY = borderBounds.Y;
 			var titleY = borderBounds.Y;

+ 3 - 2
Terminal.Gui/View/ViewDrawing.cs

@@ -384,12 +384,13 @@ namespace Terminal.Gui {
 				}
 				}
 			}
 			}
 
 
-			// Invoke DrawContentCompleteEvent
-			OnDrawContentComplete (bounds);
 			Driver.Clip = prevClip;
 			Driver.Clip = prevClip;
 
 
 			OnRenderLineCanvas ();
 			OnRenderLineCanvas ();
 
 
+			// Invoke DrawContentCompleteEvent
+			OnDrawContentComplete (bounds);
+
 			// BUGBUG: v2 - We should be able to use View.SetClip here and not have to resort to knowing Driver details.
 			// BUGBUG: v2 - We should be able to use View.SetClip here and not have to resort to knowing Driver details.
 			ClearLayoutNeeded ();
 			ClearLayoutNeeded ();
 			ClearNeedsDisplay ();
 			ClearNeedsDisplay ();

+ 1 - 2
Terminal.Gui/Views/Menu.cs

@@ -537,7 +537,6 @@ namespace Terminal.Gui {
 
 
 		public override void Redraw (Rect bounds)
 		public override void Redraw (Rect bounds)
 		{
 		{
-		
 			if (barItems.Children == null) {
 			if (barItems.Children == null) {
 				return;
 				return;
 			}
 			}
@@ -547,6 +546,7 @@ namespace Terminal.Gui {
 			Driver.SetAttribute (GetNormalColor ());
 			Driver.SetAttribute (GetNormalColor ());
 
 
 			OnDrawFrames ();
 			OnDrawFrames ();
+			OnRenderLineCanvas ();
 
 
 			for (int i = Bounds.Y; i < barItems.Children.Length; i++) {
 			for (int i = Bounds.Y; i < barItems.Children.Length; i++) {
 				if (i < 0)
 				if (i < 0)
@@ -646,7 +646,6 @@ namespace Terminal.Gui {
 			}
 			}
 			Driver.Clip = savedClip;
 			Driver.Clip = savedClip;
 
 
-			OnRenderLineCanvas ();
 			PositionCursor ();
 			PositionCursor ();
 		}
 		}
 
 

+ 79 - 79
UnitTests/Views/ContextMenuTests.cs

@@ -904,84 +904,84 @@ namespace Terminal.Gui.ViewsTests {
 		}
 		}
 
 
 		// BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why
 		// BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why
-//		[Fact, AutoInitShutdown]
-//		public void Draw_A_ContextManu_Over_A_Dialog ()
-//		{
-//			var top = Application.Top;
-//			var win = new Window ();
-//			top.Add (win);
-//			Application.Begin (top);
-//			((FakeDriver)Application.Driver).SetBufferSize (20, 15);
-
-//			Assert.Equal (new Rect (0, 0, 20, 15), win.Frame);
-//			TestHelpers.AssertDriverContentsWithFrameAre (@"
-//┌──────────────────┐
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//└──────────────────┘", output);
-
-//			var dialog = new Dialog () { X = 2, Y = 2, Width = 15, Height = 4 };
-//			dialog.Add (new TextField ("Test") { X = Pos.Center (), Width = 10 });
-//			var rs = Application.Begin (dialog);
-
-//			Assert.Equal (new Rect (2, 2, 15, 4), dialog.Frame);
-//			TestHelpers.AssertDriverContentsWithFrameAre (@"
-//┌──────────────────┐
-//│                  │
-//│ ┌─────────────┐  │
-//│ │ Test        │  │
-//│ │             │  │
-//│ └─────────────┘  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//└──────────────────┘", output);
-
-//			ReflectionTools.InvokePrivate (
-//				typeof (Application),
-//				"ProcessMouseEvent",
-//				new MouseEvent () {
-//					X = 9,
-//					Y = 3,
-//					Flags = MouseFlags.Button3Clicked
-//				});
-
-//			var firstIteration = false;
-//			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
-//			TestHelpers.AssertDriverContentsWithFrameAre (@"
-//┌──────────────────┐
-//│                  │
-//│ ┌─────────────┐  │
-//│ │ Test        │  │
-//┌───────────────────
-//│ Select All   Ctrl+
-//│ Delete All   Ctrl+
-//│ Copy         Ctrl+
-//│ Cut          Ctrl+
-//│ Paste        Ctrl+
-//│ Undo         Ctrl+
-//│ Redo         Ctrl+
-//└───────────────────
-//│                  │
-//└──────────────────┘", output);
-
-//			Application.End (rs);
-//		}
+		[Fact, AutoInitShutdown]
+		public void Draw_A_ContextManu_Over_A_Dialog ()
+		{
+			var top = Application.Top;
+			var win = new Window ();
+			top.Add (win);
+			Application.Begin (top);
+			((FakeDriver)Application.Driver).SetBufferSize (20, 15);
+
+			Assert.Equal (new Rect (0, 0, 20, 15), win.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			var dialog = new Dialog () { X = 2, Y = 2, Width = 15, Height = 4 };
+			dialog.Add (new TextField ("Test") { X = Pos.Center (), Width = 10 });
+			var rs = Application.Begin (dialog);
+
+			Assert.Equal (new Rect (2, 2, 15, 4), dialog.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│                  │
+│ ┌─────────────┐  │
+│ │ Test        │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 9,
+					Y = 3,
+					Flags = MouseFlags.Button3Clicked
+				});
+
+			var firstIteration = false;
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│                  │
+│ ┌─────────────┐  │
+│ │ Test        │  │
+┌───────────────────
+│ Select All   Ctrl+
+│ Delete All   Ctrl+
+│ Copy         Ctrl+
+│ Cut          Ctrl+
+│ Paste        Ctrl+
+│ Undo         Ctrl+
+│ Redo         Ctrl+
+└───────────────────
+│                  │
+└──────────────────┘", output);
+
+			Application.End (rs);
+		}
 	}
 	}
 }
 }

+ 1 - 1
UnitTests/Views/MenuTests.cs

@@ -1848,7 +1848,7 @@ Edit
  File                         
  File                         
 ┌────────────────────────────┐
 ┌────────────────────────────┐
 │ Open   Open a file  Ctrl+O │
 │ Open   Open a file  Ctrl+O │
-│────────────────────────────│
+├────────────────────────────┤
 │ Quit                       │
 │ Quit                       │
 └────────────────────────────┘", output);
 └────────────────────────────┘", output);
 		}
 		}

+ 256 - 256
UnitTests/Views/ToplevelTests.cs

@@ -1033,137 +1033,137 @@ namespace Terminal.Gui.ViewsTests {
 		}
 		}
 
 
 		// BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why
 		// BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why
-		//[Fact, AutoInitShutdown]
-		//public void Toplevel_Inside_ScrollView_MouseGrabView ()
-		//{
-		//	var scrollView = new ScrollView () {
-		//		X = 3,
-		//		Y = 3,
-		//		Width = 40,
-		//		Height = 16,
-		//		ContentSize = new Size (200, 100)
-		//	};
-		//	var win = new Window () { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) };
-		//	scrollView.Add (win);
-		//	var top = Application.Top;
-		//	top.Add (scrollView);
-		//	Application.Begin (top);
-
-		//	Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
-		//	Assert.Equal (new Rect (3, 3, 40, 16), scrollView.Frame);
-		//	Assert.Equal (new Rect (0, 0, 200, 100), scrollView.Subviews [0].Frame);
-		//	Assert.Equal (new Rect (3, 3, 194, 94), win.Frame);
-		//	TestHelpers.AssertDriverContentsWithFrameAre (@"
-  //
-  //
-  //
-  //    ┌───────────────────────────────────┴
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ░
-  //    │                                   ▼
-  // ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output);
-
-		//	ReflectionTools.InvokePrivate (
-		//		typeof (Application),
-		//		"ProcessMouseEvent",
-		//		new MouseEvent () {
-		//			X = 6,
-		//			Y = 6,
-		//			Flags = MouseFlags.Button1Pressed
-		//		});
-		//	Assert.Equal (win, Application.MouseGrabView);
-		//	Assert.Equal (new Rect (3, 3, 194, 94), win.Frame);
-
-		//	ReflectionTools.InvokePrivate (
-		//		typeof (Application),
-		//		"ProcessMouseEvent",
-		//		new MouseEvent () {
-		//			X = 9,
-		//			Y = 9,
-		//			Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-		//		});
-		//	Assert.Equal (win, Application.MouseGrabView);
-		//	top.SetNeedsLayout ();
-		//	top.LayoutSubviews ();
-		//	Assert.Equal (new Rect (6, 6, 191, 91), win.Frame);
-		//	Application.Refresh ();
-		//	TestHelpers.AssertDriverContentsWithFrameAre (@"
-  //
-  //
-  //
-  //
-  //
-  //
-  //       ┌────────────────────────────────░
-  //       │                                ░
-  //       │                                ░
-  //       │                                ░
-  //       │                                ░
-  //       │                                ░
-  //       │                                ░
-  //       │                                ░
-  //       │                                ▼
-  // ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output);
-
-		//	ReflectionTools.InvokePrivate (
-		//		typeof (Application),
-		//		"ProcessMouseEvent",
-		//		new MouseEvent () {
-		//			X = 5,
-		//			Y = 5,
-		//			Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
-		//		});
-		//	Assert.Equal (win, Application.MouseGrabView);
-		//	top.SetNeedsLayout ();
-		//	top.LayoutSubviews ();
-		//	Assert.Equal (new Rect (2, 2, 195, 95), win.Frame);
-		//	Application.Refresh ();
-		//	TestHelpers.AssertDriverContentsWithFrameAre (@"
-  //
-  //
-  //   ┌────────────────────────────────────│
-  //   │                                    ┴
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ░
-  //   │                                    ▼
-  // ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output);
-
-		//	ReflectionTools.InvokePrivate (
-		//		typeof (Application),
-		//		"ProcessMouseEvent",
-		//		new MouseEvent () {
-		//			X = 5,
-		//			Y = 5,
-		//			Flags = MouseFlags.Button1Released
-		//		});
-		//	Assert.Null (Application.MouseGrabView);
-
-		//	ReflectionTools.InvokePrivate (
-		//		typeof (Application),
-		//		"ProcessMouseEvent",
-		//		new MouseEvent () {
-		//			X = 4,
-		//			Y = 4,
-		//			Flags = MouseFlags.ReportMousePosition
-		//		});
-		//	Assert.Equal (scrollView, Application.MouseGrabView);
-		//}
+		[Fact, AutoInitShutdown]
+		public void Toplevel_Inside_ScrollView_MouseGrabView ()
+		{
+			var scrollView = new ScrollView () {
+				X = 3,
+				Y = 3,
+				Width = 40,
+				Height = 16,
+				ContentSize = new Size (200, 100)
+			};
+			var win = new Window () { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) };
+			scrollView.Add (win);
+			var top = Application.Top;
+			top.Add (scrollView);
+			Application.Begin (top);
+
+			Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
+			Assert.Equal (new Rect (3, 3, 40, 16), scrollView.Frame);
+			Assert.Equal (new Rect (0, 0, 200, 100), scrollView.Subviews [0].Frame);
+			Assert.Equal (new Rect (3, 3, 194, 94), win.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+                                          ▲
+                                          ┬
+                                          │
+      ┌───────────────────────────────────┴
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ░
+      │                                   ▼
+   ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 6,
+					Y = 6,
+					Flags = MouseFlags.Button1Pressed
+				});
+			Assert.Equal (win, Application.MouseGrabView);
+			Assert.Equal (new Rect (3, 3, 194, 94), win.Frame);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 9,
+					Y = 9,
+					Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+				});
+			Assert.Equal (win, Application.MouseGrabView);
+			top.SetNeedsLayout ();
+			top.LayoutSubviews ();
+			Assert.Equal (new Rect (6, 6, 191, 91), win.Frame);
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+                                          ▲
+                                          ┬
+                                          │
+                                          ┴
+                                          ░
+                                          ░
+         ┌────────────────────────────────░
+         │                                ░
+         │                                ░
+         │                                ░
+         │                                ░
+         │                                ░
+         │                                ░
+         │                                ░
+         │                                ▼
+   ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 5,
+					Y = 5,
+					Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
+				});
+			Assert.Equal (win, Application.MouseGrabView);
+			top.SetNeedsLayout ();
+			top.LayoutSubviews ();
+			Assert.Equal (new Rect (2, 2, 195, 95), win.Frame);
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+                                          ▲
+                                          ┬
+     ┌────────────────────────────────────│
+     │                                    ┴
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ░
+     │                                    ▼
+   ◄├──────┤░░░░░░░░░░░░░░░░░░░░░░░░░░░░░► ", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 5,
+					Y = 5,
+					Flags = MouseFlags.Button1Released
+				});
+			Assert.Null (Application.MouseGrabView);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 4,
+					Y = 4,
+					Flags = MouseFlags.ReportMousePosition
+				});
+			Assert.Equal (scrollView, Application.MouseGrabView);
+		}
 
 
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void Dialog_Bounds_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom ()
 		public void Dialog_Bounds_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom ()
@@ -1368,131 +1368,131 @@ namespace Terminal.Gui.ViewsTests {
 
 
 			Application.End (rs);
 			Application.End (rs);
 		}
 		}
-		
+
 		// BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why
 		// BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why
-//		[Fact, AutoInitShutdown]
-//		public void Draw_A_Top_Subview_On_A_Dialog ()
-//		{
-//			var top = Application.Top;
-//			var win = new Window () ;
-//			top.Add (win);
-//			Application.Begin (top);
-//			((FakeDriver)Application.Driver).SetBufferSize (20, 20);
-
-//			Assert.Equal (new Rect (0, 0, 20, 20), win.Frame);
-//			TestHelpers.AssertDriverContentsWithFrameAre (@"
-//┌──────────────────┐
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//└──────────────────┘", output);
-
-//			var btnPopup = new Button ("Popup");
-//			btnPopup.Clicked += (s, e) => {
-//				var viewToScreen = btnPopup.ViewToScreen (top.Frame);
-//				var view = new View () {
-//					X = 1,
-//					Y = viewToScreen.Y + 1,
-//					Width = 18,
-//					Height = 5,
-//					BorderStyle = LineStyle.Single 
-//				};
-//				Application.Current.DrawContentComplete += Current_DrawContentComplete;
-//				top.Add (view);
-
-//				void Current_DrawContentComplete (object sender, DrawEventArgs e)
-//				{
-//					Assert.Equal (new Rect (1, 14, 18, 5), view.Frame);
-
-//					var savedClip = Application.Driver.Clip;
-//					Application.Driver.Clip = top.Frame;
-//					view.Redraw (view.Bounds);
-//					top.Move (2, 15);
-//					View.Driver.AddStr ("One");
-//					top.Move (2, 16);
-//					View.Driver.AddStr ("Two");
-//					top.Move (2, 17);
-//					View.Driver.AddStr ("Three");
-//					Application.Driver.Clip = savedClip;
-
-//					Application.Current.DrawContentComplete -= Current_DrawContentComplete;
-//				}
-//			};
-//			var dialog = new Dialog (btnPopup) { Width = 15, Height = 10 };
-//			var rs = Application.Begin (dialog);
-
-//			Assert.Equal (new Rect (2, 5, 15, 10), dialog.Frame);
-//			TestHelpers.AssertDriverContentsWithFrameAre (@"
-//┌──────────────────┐
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│ ┌─────────────┐  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │  [ Popup ]  │  │
-//│ └─────────────┘  │
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//└──────────────────┘", output);
-
-//			ReflectionTools.InvokePrivate (
-//				typeof (Application),
-//				"ProcessMouseEvent",
-//				new MouseEvent () {
-//					X = 9,
-//					Y = 13,
-//					Flags = MouseFlags.Button1Clicked
-//				});
-
-//			var firstIteration = false;
-//			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
-//			TestHelpers.AssertDriverContentsWithFrameAre (@"
-//┌──────────────────┐
-//│                  │
-//│                  │
-//│                  │
-//│                  │
-//│ ┌─────────────┐  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │             │  │
-//│ │  [ Popup ]  │  │
-//│┌────────────────┐│
-//││One             ││
-//││Two             ││
-//││Three           ││
-//│└────────────────┘│
-//└──────────────────┘", output);
-
-//			Application.End (rs);
-//		}
+		[Fact, AutoInitShutdown]
+		public void Draw_A_Top_Subview_On_A_Dialog ()
+		{
+			var top = Application.Top;
+			var win = new Window ();
+			top.Add (win);
+			Application.Begin (top);
+			((FakeDriver)Application.Driver).SetBufferSize (20, 20);
+
+			Assert.Equal (new Rect (0, 0, 20, 20), win.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			var btnPopup = new Button ("Popup");
+			btnPopup.Clicked += (s, e) => {
+				var viewToScreen = btnPopup.ViewToScreen (top.Frame);
+				var view = new View () {
+					X = 1,
+					Y = viewToScreen.Y + 1,
+					Width = 18,
+					Height = 5,
+					BorderStyle = LineStyle.Single
+				};
+				Application.Current.DrawContentComplete += Current_DrawContentComplete;
+				top.Add (view);
+
+				void Current_DrawContentComplete (object sender, DrawEventArgs e)
+				{
+					Assert.Equal (new Rect (1, 14, 18, 5), view.Frame);
+
+					var savedClip = Application.Driver.Clip;
+					Application.Driver.Clip = top.Frame;
+					view.Redraw (view.Bounds);
+					top.Move (2, 15);
+					View.Driver.AddStr ("One");
+					top.Move (2, 16);
+					View.Driver.AddStr ("Two");
+					top.Move (2, 17);
+					View.Driver.AddStr ("Three");
+					Application.Driver.Clip = savedClip;
+
+					Application.Current.DrawContentComplete -= Current_DrawContentComplete;
+				}
+			};
+			var dialog = new Dialog (btnPopup) { Width = 15, Height = 10 };
+			var rs = Application.Begin (dialog);
+
+			Assert.Equal (new Rect (2, 5, 15, 10), dialog.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│                  │
+│                  │
+│                  │
+│                  │
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │  [ Popup ]  │  │
+│ └─────────────┘  │
+│                  │
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			ReflectionTools.InvokePrivate (
+				typeof (Application),
+				"ProcessMouseEvent",
+				new MouseEvent () {
+					X = 9,
+					Y = 13,
+					Flags = MouseFlags.Button1Clicked
+				});
+
+			var firstIteration = false;
+			Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│                  │
+│                  │
+│                  │
+│                  │
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │  [ Popup ]  │  │
+│┌────────────────┐│
+││One             ││
+││Two             ││
+││Three           ││
+│└────────────────┘│
+└──────────────────┘", output);
+
+			Application.End (rs);
+		}
 	}
 	}
 }
 }