From 5ad8a8a2fbf631cc5877cee518215d8f15d45abb Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 20 Mar 2019 10:08:10 +0100 Subject: [PATCH] SEBWIN-117: Corrected implementation of browser window to automatically resize itself on display rotation. Decided to use WPF's SystemParameters nonetheless by only accessing it after the working area has been initialized. --- SafeExamBrowser.Client/ClientController.cs | 4 +- .../Operations/ShellOperation.cs | 1 - .../UserInterface/Shell/IActionCenter.cs | 10 ++--- .../UserInterface/Shell/ITaskbar.cs | 7 +--- .../ActionCenter.xaml.cs | 24 +++++------ .../BrowserWindow.xaml.cs | 41 +++++++++++++------ .../RuntimeWindow.xaml.cs | 8 ---- .../SplashScreen.xaml.cs | 8 ---- 8 files changed, 46 insertions(+), 57 deletions(-) diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 2bc2332c..1322556b 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -324,8 +324,8 @@ namespace SafeExamBrowser.Client logger.Info("Reinitializing working area..."); displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight()); logger.Info("Reinitializing shell..."); + actionCenter.InitializeBounds(); taskbar.InitializeBounds(); - actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight()); logger.Info("Desktop successfully restored."); } @@ -369,8 +369,8 @@ namespace SafeExamBrowser.Client logger.Info("Reinitializing working area..."); displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight()); logger.Info("Reinitializing shell..."); + actionCenter.InitializeBounds(); taskbar.InitializeBounds(); - actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight()); logger.Info("Desktop successfully restored."); } diff --git a/SafeExamBrowser.Client/Operations/ShellOperation.cs b/SafeExamBrowser.Client/Operations/ShellOperation.cs index 745d68ab..79f6ac56 100644 --- a/SafeExamBrowser.Client/Operations/ShellOperation.cs +++ b/SafeExamBrowser.Client/Operations/ShellOperation.cs @@ -106,7 +106,6 @@ namespace SafeExamBrowser.Client.Operations { logger.Info("Initializing action center..."); actionCenter.InitializeText(text); - actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight()); InitializeAboutNotificationForActionCenter(); InitializeClockForActionCenter(); diff --git a/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs b/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs index 778a5f61..53f48909 100644 --- a/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs @@ -51,6 +51,11 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell /// void Hide(); + /// + /// Moves the action center to the left of the screen and resizes it accordingly. + /// + void InitializeBounds(); + /// /// Initializes all text elements in the action center. /// @@ -61,11 +66,6 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell /// void Register(IActionCenterActivator activator); - /// - /// Informs the action center about the relative height (i.e. height in logical pixels) of the taskbar. - /// - void UpdateTaskbarHeight(int height); - /// /// Makes the action center visible. /// diff --git a/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs b/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs index df736c3a..fc30c317 100644 --- a/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs @@ -52,12 +52,7 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell int GetAbsoluteHeight(); /// - /// Returns the relative height of the taskbar (i.e. in logical pixels). - /// - int GetRelativeHeight(); - - /// - /// Moves the taskbar to the bottom of and resizes it according to the current working area. + /// Moves the taskbar to the bottom of the screen and resizes it accordingly. /// void InitializeBounds(); diff --git a/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs index edf25954..8bd13c35 100644 --- a/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs @@ -17,8 +17,6 @@ namespace SafeExamBrowser.UserInterface.Desktop { public partial class ActionCenter : Window, IActionCenter { - private int taskbarHeight = 40; - public bool ShowClock { set { Dispatcher.Invoke(() => Clock.Visibility = value ? Visibility.Visible : Visibility.Collapsed); } @@ -66,6 +64,16 @@ namespace SafeExamBrowser.UserInterface.Desktop Dispatcher.Invoke(HideAnimated); } + public void InitializeBounds() + { + Dispatcher.Invoke(() => + { + Height = SystemParameters.WorkArea.Height; + Top = 0; + Left = -Width; + }); + } + public void InitializeText(IText text) { QuitButton.ToolTip = text.Get(TextKey.Shell_QuitButton); @@ -84,11 +92,6 @@ namespace SafeExamBrowser.UserInterface.Desktop Dispatcher.Invoke(ShowAnimated); } - public void UpdateTaskbarHeight(int height) - { - taskbarHeight = height; - } - private void HideAnimated() { var storyboard = new Storyboard(); @@ -130,13 +133,6 @@ namespace SafeExamBrowser.UserInterface.Desktop storyboard.Begin(); } - private void InitializeBounds() - { - Height = SystemParameters.PrimaryScreenHeight - taskbarHeight; - Top = 0; - Left = -Width; - } - private void ShowAnimation_Completed(object sender, EventArgs e) { Activate(); diff --git a/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs index 878f017e..68965b8b 100644 --- a/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs @@ -129,6 +129,7 @@ namespace SafeExamBrowser.UserInterface.Desktop } RegisterEvents(); + InitializeBounds(); ApplySettings(); LoadIcons(); LoadText(); @@ -154,6 +155,14 @@ namespace SafeExamBrowser.UserInterface.Desktop } } + private void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(SystemParameters.WorkArea)) + { + Dispatcher.InvokeAsync(InitializeBounds); + } + } + private void UrlTextBox_GotMouseCapture(object sender, MouseEventArgs e) { if (UrlTextBox.Tag as bool? != true) @@ -185,6 +194,7 @@ namespace SafeExamBrowser.UserInterface.Desktop MenuPopup.Opened += (o, args) => MenuButton.Background = Brushes.LightGray; KeyUp += BrowserWindow_KeyUp; ReloadButton.Click += (o, args) => ReloadRequested?.Invoke(); + SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged; UrlTextBox.GotKeyboardFocus += (o, args) => UrlTextBox.SelectAll(); UrlTextBox.GotMouseCapture += UrlTextBox_GotMouseCapture; UrlTextBox.LostKeyboardFocus += (o, args) => UrlTextBox.Tag = null; @@ -197,14 +207,30 @@ namespace SafeExamBrowser.UserInterface.Desktop } private void ApplySettings() + { + UrlTextBox.IsEnabled = WindowSettings.AllowAddressBar; + + ReloadButton.IsEnabled = WindowSettings.AllowReloading; + ReloadButton.Visibility = WindowSettings.AllowReloading ? Visibility.Visible : Visibility.Collapsed; + + BackwardButton.IsEnabled = WindowSettings.AllowBackwardNavigation; + BackwardButton.Visibility = WindowSettings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed; + + ForwardButton.IsEnabled = WindowSettings.AllowForwardNavigation; + ForwardButton.Visibility = WindowSettings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed; + } + + private void InitializeBounds() { if (isMainWindow) { if (WindowSettings.FullScreenMode) { - MaxHeight = SystemParameters.WorkArea.Height; + Top = 0; + Left = 0; + Height = SystemParameters.WorkArea.Height; + Width = SystemParameters.WorkArea.Width; ResizeMode = ResizeMode.NoResize; - WindowState = WindowState.Maximized; WindowStyle = WindowStyle.None; } else @@ -219,17 +245,6 @@ namespace SafeExamBrowser.UserInterface.Desktop Height = SystemParameters.WorkArea.Height; Width = SystemParameters.WorkArea.Width / 2; } - - UrlTextBox.IsEnabled = WindowSettings.AllowAddressBar; - - ReloadButton.IsEnabled = WindowSettings.AllowReloading; - ReloadButton.Visibility = WindowSettings.AllowReloading ? Visibility.Visible : Visibility.Collapsed; - - BackwardButton.IsEnabled = WindowSettings.AllowBackwardNavigation; - BackwardButton.Visibility = WindowSettings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed; - - ForwardButton.IsEnabled = WindowSettings.AllowForwardNavigation; - ForwardButton.Visibility = WindowSettings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed; } private void LoadIcons() diff --git a/SafeExamBrowser.UserInterface.Desktop/RuntimeWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/RuntimeWindow.xaml.cs index 914186f7..2e0ee802 100644 --- a/SafeExamBrowser.UserInterface.Desktop/RuntimeWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/RuntimeWindow.xaml.cs @@ -44,8 +44,6 @@ namespace SafeExamBrowser.UserInterface.Desktop InitializeComponent(); InitializeRuntimeWindow(); - - Loaded += RuntimeWindow_Loaded; } public void BringToForeground() @@ -146,11 +144,5 @@ namespace SafeExamBrowser.UserInterface.Desktop Topmost = false; #endif } - - private void RuntimeWindow_Loaded(object sender, RoutedEventArgs e) - { - Left = (SystemParameters.WorkArea.Right / 2) - (Width / 2); - Top = (SystemParameters.WorkArea.Bottom / 2) - (Height / 2); - } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/SplashScreen.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/SplashScreen.xaml.cs index 550e6b95..13e4446a 100644 --- a/SafeExamBrowser.UserInterface.Desktop/SplashScreen.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/SplashScreen.xaml.cs @@ -49,8 +49,6 @@ namespace SafeExamBrowser.UserInterface.Desktop InitializeComponent(); InitializeSplashScreen(); - - Loaded += SplashScreen_Loaded; } public void BringToForeground() @@ -130,11 +128,5 @@ namespace SafeExamBrowser.UserInterface.Desktop InfoTextBlock.Inlines.Add(new Run(appConfig.ProgramCopyright) { FontSize = 10 }); } } - - private void SplashScreen_Loaded(object sender, RoutedEventArgs e) - { - Left = (SystemParameters.WorkArea.Right / 2) - (Width / 2); - Top = (SystemParameters.WorkArea.Bottom / 2) - (Height / 2); - } } }