2017-07-05 17:21:52 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-07-05 17:21:52 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
using System.ComponentModel;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
using System.Windows;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2017-08-11 08:28:17 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2019-03-06 16:10:00 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Shell;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Shell.Events;
|
2019-01-11 15:32:47 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Desktop.Utilities;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
2019-01-11 15:32:47 +01:00
|
|
|
|
namespace SafeExamBrowser.UserInterface.Desktop
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
public partial class Taskbar : Window, ITaskbar
|
|
|
|
|
{
|
2018-06-21 08:54:43 +02:00
|
|
|
|
private bool allowClose;
|
2017-08-11 08:28:17 +02:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
|
2019-01-11 08:25:40 +01:00
|
|
|
|
public bool ShowClock
|
|
|
|
|
{
|
|
|
|
|
set { Dispatcher.Invoke(() => Clock.Visibility = value ? Visibility.Visible : Visibility.Collapsed); }
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
public event QuitButtonClickedEventHandler QuitButtonClicked;
|
|
|
|
|
|
2017-08-11 08:28:17 +02:00
|
|
|
|
public Taskbar(ILogger logger)
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
2017-08-22 09:37:17 +02:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
2019-03-15 11:38:59 +01:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeTaskbar();
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 11:43:52 +01:00
|
|
|
|
public void AddApplicationControl(IApplicationControl control)
|
2017-07-11 15:29:29 +02:00
|
|
|
|
{
|
2019-03-08 11:43:52 +01:00
|
|
|
|
if (control is UIElement uiElement)
|
2017-07-11 15:29:29 +02:00
|
|
|
|
{
|
2018-02-19 14:36:00 +01:00
|
|
|
|
ApplicationStackPanel.Children.Add(uiElement);
|
2017-07-11 15:29:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 11:43:52 +01:00
|
|
|
|
public void AddNotificationControl(INotificationControl control)
|
2017-07-17 16:59:50 +02:00
|
|
|
|
{
|
2019-03-08 11:43:52 +01:00
|
|
|
|
if (control is UIElement uiElement)
|
2017-07-17 16:59:50 +02:00
|
|
|
|
{
|
2018-02-19 14:36:00 +01:00
|
|
|
|
NotificationStackPanel.Children.Add(uiElement);
|
2017-07-17 16:59:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-15 15:30:31 +02:00
|
|
|
|
public void AddSystemControl(ISystemControl control)
|
|
|
|
|
{
|
2018-02-19 14:36:00 +01:00
|
|
|
|
if (control is UIElement uiElement)
|
2017-08-15 15:30:31 +02:00
|
|
|
|
{
|
2018-02-19 14:36:00 +01:00
|
|
|
|
SystemControlStackPanel.Children.Add(uiElement);
|
2017-08-15 15:30:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
public new void Close()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Close);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 14:16:47 +02:00
|
|
|
|
public int GetAbsoluteHeight()
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
2017-07-26 14:36:20 +02:00
|
|
|
|
return Dispatcher.Invoke(() =>
|
2017-07-20 14:16:47 +02:00
|
|
|
|
{
|
2017-08-22 10:29:00 +02:00
|
|
|
|
var height = (int) this.TransformToPhysical(Width, Height).Y;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
logger.Info($"Calculated physical taskbar height is {height}px.");
|
2017-07-20 14:16:47 +02:00
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
return height;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitializeBounds()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
2017-08-22 10:29:00 +02:00
|
|
|
|
Width = SystemParameters.WorkArea.Right;
|
|
|
|
|
Left = SystemParameters.WorkArea.Right - Width;
|
|
|
|
|
Top = SystemParameters.WorkArea.Bottom;
|
2017-08-11 08:28:17 +02:00
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
var position = this.TransformToPhysical(Left, Top);
|
|
|
|
|
var size = this.TransformToPhysical(Width, Height);
|
2017-08-11 08:28:17 +02:00
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
logger.Info($"Set taskbar bounds to {Width}x{Height} at ({Left}/{Top}), in physical pixels: {size.X}x{size.Y} at ({position.X}/{position.Y}).");
|
2017-07-26 14:36:20 +02:00
|
|
|
|
});
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
2017-08-17 12:17:58 +02:00
|
|
|
|
|
2019-03-15 11:38:59 +01:00
|
|
|
|
public void InitializeText(IText text)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
QuitButton.ToolTip = text.Get(TextKey.Shell_QuitButton);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 16:10:00 +01:00
|
|
|
|
public new void Show()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(base.Show);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 08:54:43 +02:00
|
|
|
|
private void QuitButton_Clicked(CancelEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
QuitButtonClicked?.Invoke(args);
|
|
|
|
|
allowClose = !args.Cancel;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
private void Taskbar_Closing(object sender, CancelEventArgs e)
|
2017-08-17 12:17:58 +02:00
|
|
|
|
{
|
2018-06-21 08:54:43 +02:00
|
|
|
|
if (!allowClose)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 10:29:00 +02:00
|
|
|
|
foreach (var child in SystemControlStackPanel.Children)
|
|
|
|
|
{
|
2018-02-19 14:36:00 +01:00
|
|
|
|
if (child is ISystemControl systemControl)
|
2017-08-22 10:29:00 +02:00
|
|
|
|
{
|
2018-02-19 14:36:00 +01:00
|
|
|
|
systemControl.Close();
|
2017-08-22 10:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-17 12:17:58 +02:00
|
|
|
|
}
|
2019-03-15 11:38:59 +01:00
|
|
|
|
|
|
|
|
|
private void InitializeTaskbar()
|
|
|
|
|
{
|
|
|
|
|
Closing += Taskbar_Closing;
|
|
|
|
|
Loaded += (o, args) => InitializeBounds();
|
|
|
|
|
QuitButton.Clicked += QuitButton_Clicked;
|
|
|
|
|
}
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|