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.

This commit is contained in:
dbuechel 2019-03-20 10:08:10 +01:00
parent 13832cb65c
commit 5ad8a8a2fb
8 changed files with 46 additions and 57 deletions

View file

@ -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.");
}

View file

@ -106,7 +106,6 @@ namespace SafeExamBrowser.Client.Operations
{
logger.Info("Initializing action center...");
actionCenter.InitializeText(text);
actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight());
InitializeAboutNotificationForActionCenter();
InitializeClockForActionCenter();

View file

@ -51,6 +51,11 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell
/// </summary>
void Hide();
/// <summary>
/// Moves the action center to the left of the screen and resizes it accordingly.
/// </summary>
void InitializeBounds();
/// <summary>
/// Initializes all text elements in the action center.
/// </summary>
@ -61,11 +66,6 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell
/// </summary>
void Register(IActionCenterActivator activator);
/// <summary>
/// Informs the action center about the relative height (i.e. height in logical pixels) of the taskbar.
/// </summary>
void UpdateTaskbarHeight(int height);
/// <summary>
/// Makes the action center visible.
/// </summary>

View file

@ -52,12 +52,7 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell
int GetAbsoluteHeight();
/// <summary>
/// Returns the relative height of the taskbar (i.e. in logical pixels).
/// </summary>
int GetRelativeHeight();
/// <summary>
/// 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.
/// </summary>
void InitializeBounds();

View file

@ -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();

View file

@ -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()

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}