public void Internal_Tests() { var top = new Toplevel(); var eventInvoked = ""; top.ChildUnloaded += (e) => eventInvoked = "ChildUnloaded"; top.OnChildUnloaded(top); Assert.Equal("ChildUnloaded", eventInvoked); top.ChildLoaded += (e) => eventInvoked = "ChildLoaded"; top.OnChildLoaded(top); Assert.Equal("ChildLoaded", eventInvoked); top.Closed += (e) => eventInvoked = "Closed"; top.OnClosed(top); Assert.Equal("Closed", eventInvoked); top.Closing += (e) => eventInvoked = "Closing"; top.OnClosing(new ToplevelClosingEventArgs(top)); Assert.Equal("Closing", eventInvoked); top.AllChildClosed += () => eventInvoked = "AllChildClosed"; top.OnAllChildClosed(); Assert.Equal("AllChildClosed", eventInvoked); top.ChildClosed += (e) => eventInvoked = "ChildClosed"; top.OnChildClosed(top); Assert.Equal("ChildClosed", eventInvoked); top.Deactivate += (e) => eventInvoked = "Deactivate"; top.OnDeactivate(top); Assert.Equal("Deactivate", eventInvoked); top.Activate += (e) => eventInvoked = "Activate"; top.OnActivate(top); Assert.Equal("Activate", eventInvoked); top.Loaded += () => eventInvoked = "Loaded"; top.OnLoaded(); Assert.Equal("Loaded", eventInvoked); top.Ready += () => eventInvoked = "Ready"; top.OnReady(); Assert.Equal("Ready", eventInvoked); top.Unloaded += () => eventInvoked = "Unloaded"; top.OnUnloaded(); Assert.Equal("Unloaded", eventInvoked); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); top.RemoveMenuStatusBar(top.MenuBar); Assert.Null(top.MenuBar); top.RemoveMenuStatusBar(top.StatusBar); Assert.Null(top.StatusBar); Application.Begin(top); Assert.Equal(top, Application.Top); // top is Application.Top without menu and status bar. var supView = top.EnsureVisibleBounds(top, 2, 2, out int nx, out int ny, out View mb, out View sb); Assert.Equal(Application.Top, supView); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.Null(sb); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); // top is Application.Top with a menu and without status bar. top.EnsureVisibleBounds(top, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.Null(sb); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); // top is Application.Top with a menu and status bar. top.EnsureVisibleBounds(top, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.NotNull(sb); top.RemoveMenuStatusBar(top.MenuBar); Assert.Null(top.MenuBar); // top is Application.Top without a menu and with a status bar. top.EnsureVisibleBounds(top, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.NotNull(sb); top.RemoveMenuStatusBar(top.StatusBar); Assert.Null(top.StatusBar); Assert.Null(top.MenuBar); var win = new Window() { Width = Dim.Fill(), Height = Dim.Fill() }; top.Add(win); top.LayoutSubviews(); // The SuperView is always the same regardless of the caller. supView = top.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(Application.Top, supView); supView = win.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(Application.Top, supView); // top is Application.Top without menu and status bar. top.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.Null(sb); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); // top is Application.Top with a menu and without status bar. top.EnsureVisibleBounds(win, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.Null(sb); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); // top is Application.Top with a menu and status bar. top.EnsureVisibleBounds(win, 30, 20, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(1, ny); Assert.NotNull(mb); Assert.NotNull(sb); top.RemoveMenuStatusBar(top.MenuBar); top.RemoveMenuStatusBar(top.StatusBar); Assert.Null(top.StatusBar); Assert.Null(top.MenuBar); top.Remove(win); win = new Window() { Width = 60, Height = 15 }; top.Add(win); // top is Application.Top without menu and status bar. top.EnsureVisibleBounds(win, 0, 0, out nx, out ny, out mb, out sb); Assert.Equal(0, nx); Assert.Equal(0, ny); Assert.Null(mb); Assert.Null(sb); top.AddMenuStatusBar(new MenuBar()); Assert.NotNull(top.MenuBar); // top is Application.Top with a menu and without status bar. top.EnsureVisibleBounds(win, 2, 2, out nx, out ny, out mb, out sb); Assert.Equal(2, nx); Assert.Equal(2, ny); Assert.NotNull(mb); Assert.Null(sb); top.AddMenuStatusBar(new StatusBar()); Assert.NotNull(top.StatusBar); // top is Application.Top with a menu and status bar. top.EnsureVisibleBounds(win, 30, 20, out nx, out ny, out mb, out sb); Assert.Equal(20, nx); // 20+60=80 Assert.Equal(9, ny); // 9+15+1(mb)=25 Assert.NotNull(mb); Assert.NotNull(sb); top.PositionToplevels(); Assert.Equal(new Rect(0, 1, 60, 15), win.Frame); Assert.Null(Toplevel.dragPosition); win.MouseEvent(new MouseEvent() { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed }); Assert.Equal(new Point(6, 0), Toplevel.dragPosition); win.MouseEvent(new MouseEvent() { X = 6, Y = 0, Flags = MouseFlags.Button1Released }); Assert.Null(Toplevel.dragPosition); win.CanFocus = false; win.MouseEvent(new MouseEvent() { X = 6, Y = 0, Flags = MouseFlags.Button1Pressed }); Assert.Null(Toplevel.dragPosition); }
public void Show(Toplevel top, User user) { // Creates the top-level window to show var win = new Window("CPN app") { X = 0, Y = 1, // Leave one row for the toplevel menu // By using Dim.Fill(), it will automatically resize without manual intervention Width = Dim.Fill(), Height = Dim.Fill() }; top.Add(win); var logo = new StringBuilder(); logo.AppendLine(" ▒▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒ "); logo.AppendLine(" ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); logo.AppendLine("░▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓▓▓▓▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓▓▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓▓▓▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▒ ▓▓▓▓▓▓ ░▓▓▓▓▓"); logo.AppendLine("▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); logo.AppendLine(" ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); logo.AppendLine(" ▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ "); logo.AppendLine(" ▓▓▓▓▓▓▓ app "); Label logoLabel = new Label() { X = 15, Y = 0, Height = 16, Width = 35 }; logoLabel.Text = ustring.Make(logo.ToString()); // .Replace(" ", "\u00A0"); // \u00A0 is 'non-breaking space win.Add(logoLabel); var login = new Label("Login: "******"Password: "******"") { X = Pos.Right(password), Y = Pos.Top(login), Width = 30 }; var passText = new TextField("") { Secret = true, X = Pos.Left(loginText), Y = Pos.Top(password), Width = Dim.Width(loginText) }; Button loginButton = new Button(6, 22, "Login"); // Add some controls, win.Add( // The ones with my favorite layout system, Computed login, password, loginText, passText, // The ones laid out like an australopithecus, with Absolute positions: // new CheckBox(3, 6, "Remember me"), //new RadioGroup(3, 8, (new[] { NStack.ustring.Make("_Personal"), "_Company" })), loginButton, new Button(18, 22, "Cancel") ); loginButton.Clicked += () => { var btnText = loginButton.Text.ToString(); var l = loginText.Text.ToString(); var p = passText.Text.ToString(); var(result, loggedUser) = Controller.Login(l, p); if (result) { top.Remove(win); win.Dispose(); win.Clear(); Controller.RedirectToWindow(loggedUser); } else { MessageBox.ErrorQuery("Exception", "Błędne dane logowania.", "Ok"); } }; }