From 018e59690566a0f6652496f5ac1fce88d32337c0 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Tue, 3 Dec 2019 15:43:48 +0100 Subject: [PATCH] SEBWIN-312: Implemented icon change event for application windows and finally moved IconResource from core to application namespace. --- .../Events/IconChangedEventHandler.cs | 2 +- .../IApplication.cs | 2 +- .../IApplicationWindow.cs | 2 +- .../Resources/Icons/BitmapIconResource.cs | 13 ++----- .../Resources/Icons/EmbeddedIconResource.cs | 21 +++++++++++ .../Resources/Icons/IconResource.cs | 17 +++++++++ .../Resources/Icons/NativeIconResource.cs | 23 ++++++++++++ .../Resources/Icons/XamlIconResource.cs | 23 ++++++++++++ ...eExamBrowser.Applications.Contracts.csproj | 9 +++-- .../ExternalApplication.cs | 4 +- .../ExternalApplicationInstance.cs | 2 +- .../ExternalApplicationWindow.cs | 18 ++++++--- .../SafeExamBrowser.Applications.csproj | 4 -- SafeExamBrowser.Browser/BrowserApplication.cs | 2 +- .../BrowserApplicationInstance.cs | 2 +- .../BrowserIconResource.cs | 5 +-- .../SafeExamBrowser.Browser.csproj | 4 -- .../INotificationInfo.cs | 2 +- .../SafeExamBrowser.Client.Contracts.csproj | 4 ++ .../Notifications/AboutNotificationInfo.cs | 8 +--- .../Notifications/LogNotificationInfo.cs | 8 +--- .../IconResourceType.cs | 31 ---------------- .../SafeExamBrowser.Core.Contracts.csproj | 2 - .../Browser/IBrowserWindow.cs | 2 +- ...ExamBrowser.UserInterface.Contracts.csproj | 4 -- .../BrowserWindow.xaml.cs | 24 ++++++------ .../ActionCenterApplicationButton.xaml.cs | 4 +- .../Controls/ActionCenterAudioControl.xaml.cs | 8 ++-- .../Controls/ActionCenterQuitButton.xaml.cs | 4 +- ...ActionCenterWirelessNetworkControl.xaml.cs | 4 +- .../Controls/TaskViewWindowControl.xaml.cs | 2 +- .../TaskbarApplicationWindowButton.xaml.cs | 2 +- .../Controls/TaskbarAudioControl.xaml.cs | 8 ++-- .../Controls/TaskbarQuitButton.xaml.cs | 4 +- .../TaskbarWirelessNetworkControl.xaml.cs | 4 +- ...feExamBrowser.UserInterface.Desktop.csproj | 4 -- .../BrowserWindow.xaml.cs | 24 ++++++------ .../ActionCenterApplicationButton.xaml.cs | 4 +- .../Controls/ActionCenterAudioControl.xaml.cs | 8 ++-- .../Controls/ActionCenterQuitButton.xaml.cs | 4 +- ...ActionCenterWirelessNetworkControl.xaml.cs | 4 +- .../Controls/TaskViewWindowControl.xaml.cs | 2 +- .../TaskbarApplicationWindowButton.xaml.cs | 2 +- .../Controls/TaskbarAudioControl.xaml.cs | 8 ++-- .../Controls/TaskbarQuitButton.xaml.cs | 4 +- .../TaskbarWirelessNetworkControl.xaml.cs | 4 +- ...afeExamBrowser.UserInterface.Mobile.csproj | 4 -- ...afeExamBrowser.UserInterface.Shared.csproj | 6 +-- .../Utilities/IconResourceLoader.cs | 37 ++++++++++++------- .../INativeMethods.cs | 5 +++ .../Constants/Constant.cs | 24 ++++++++++++ SafeExamBrowser.WindowsApi/NativeMethods.cs | 17 +++++++++ 52 files changed, 265 insertions(+), 174 deletions(-) rename SafeExamBrowser.Core.Contracts/IconResource.cs => SafeExamBrowser.Applications.Contracts/Resources/Icons/BitmapIconResource.cs (56%) create mode 100644 SafeExamBrowser.Applications.Contracts/Resources/Icons/EmbeddedIconResource.cs create mode 100644 SafeExamBrowser.Applications.Contracts/Resources/Icons/IconResource.cs create mode 100644 SafeExamBrowser.Applications.Contracts/Resources/Icons/NativeIconResource.cs create mode 100644 SafeExamBrowser.Applications.Contracts/Resources/Icons/XamlIconResource.cs delete mode 100644 SafeExamBrowser.Core.Contracts/IconResourceType.cs diff --git a/SafeExamBrowser.Applications.Contracts/Events/IconChangedEventHandler.cs b/SafeExamBrowser.Applications.Contracts/Events/IconChangedEventHandler.cs index 71adaf49..50649661 100644 --- a/SafeExamBrowser.Applications.Contracts/Events/IconChangedEventHandler.cs +++ b/SafeExamBrowser.Applications.Contracts/Events/IconChangedEventHandler.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; namespace SafeExamBrowser.Applications.Contracts.Events { diff --git a/SafeExamBrowser.Applications.Contracts/IApplication.cs b/SafeExamBrowser.Applications.Contracts/IApplication.cs index a37e9c88..10adecee 100644 --- a/SafeExamBrowser.Applications.Contracts/IApplication.cs +++ b/SafeExamBrowser.Applications.Contracts/IApplication.cs @@ -9,7 +9,7 @@ using System; using System.Collections.Generic; using SafeExamBrowser.Applications.Contracts.Events; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; namespace SafeExamBrowser.Applications.Contracts { diff --git a/SafeExamBrowser.Applications.Contracts/IApplicationWindow.cs b/SafeExamBrowser.Applications.Contracts/IApplicationWindow.cs index 24a8e7ca..5ac1deb7 100644 --- a/SafeExamBrowser.Applications.Contracts/IApplicationWindow.cs +++ b/SafeExamBrowser.Applications.Contracts/IApplicationWindow.cs @@ -7,7 +7,7 @@ */ using SafeExamBrowser.Applications.Contracts.Events; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; namespace SafeExamBrowser.Applications.Contracts { diff --git a/SafeExamBrowser.Core.Contracts/IconResource.cs b/SafeExamBrowser.Applications.Contracts/Resources/Icons/BitmapIconResource.cs similarity index 56% rename from SafeExamBrowser.Core.Contracts/IconResource.cs rename to SafeExamBrowser.Applications.Contracts/Resources/Icons/BitmapIconResource.cs index beff06d3..29f6fbea 100644 --- a/SafeExamBrowser.Core.Contracts/IconResource.cs +++ b/SafeExamBrowser.Applications.Contracts/Resources/Icons/BitmapIconResource.cs @@ -8,20 +8,15 @@ using System; -namespace SafeExamBrowser.Core.Contracts +namespace SafeExamBrowser.Applications.Contracts.Resources.Icons { /// - /// Defines an icon resource, i.e. the path to and type of an icon. + /// Defines an icon resource which is a bitmap image (i.e. raster graphics). /// - public class IconResource + public class BitmapIconResource : IconResource { /// - /// Defines the data type of the resource. - /// - public IconResourceType Type { get; set; } - - /// - /// The pointing to the icon data. + /// The pointing to the image file. /// public Uri Uri { get; set; } } diff --git a/SafeExamBrowser.Applications.Contracts/Resources/Icons/EmbeddedIconResource.cs b/SafeExamBrowser.Applications.Contracts/Resources/Icons/EmbeddedIconResource.cs new file mode 100644 index 00000000..f7c05f8a --- /dev/null +++ b/SafeExamBrowser.Applications.Contracts/Resources/Icons/EmbeddedIconResource.cs @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * 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/. + */ + +namespace SafeExamBrowser.Applications.Contracts.Resources.Icons +{ + /// + /// Defines an icon resource which is a file with embedded icon data (e.g. an executable). + /// + public class EmbeddedIconResource : IconResource + { + /// + /// The full path of the file. + /// + public string FilePath { get; set; } + } +} diff --git a/SafeExamBrowser.Applications.Contracts/Resources/Icons/IconResource.cs b/SafeExamBrowser.Applications.Contracts/Resources/Icons/IconResource.cs new file mode 100644 index 00000000..4b0e292b --- /dev/null +++ b/SafeExamBrowser.Applications.Contracts/Resources/Icons/IconResource.cs @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * 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/. + */ + +namespace SafeExamBrowser.Applications.Contracts.Resources.Icons +{ + /// + /// Defines an icon resource. + /// + public abstract class IconResource + { + } +} diff --git a/SafeExamBrowser.Applications.Contracts/Resources/Icons/NativeIconResource.cs b/SafeExamBrowser.Applications.Contracts/Resources/Icons/NativeIconResource.cs new file mode 100644 index 00000000..1cd0f068 --- /dev/null +++ b/SafeExamBrowser.Applications.Contracts/Resources/Icons/NativeIconResource.cs @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * 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/. + */ + +using System; + +namespace SafeExamBrowser.Applications.Contracts.Resources.Icons +{ + /// + /// Defines an icon resource which is managed by the operating system. + /// + public class NativeIconResource : IconResource + { + /// + /// The handle of the icon. + /// + public IntPtr Handle { get; set; } + } +} diff --git a/SafeExamBrowser.Applications.Contracts/Resources/Icons/XamlIconResource.cs b/SafeExamBrowser.Applications.Contracts/Resources/Icons/XamlIconResource.cs new file mode 100644 index 00000000..fe889066 --- /dev/null +++ b/SafeExamBrowser.Applications.Contracts/Resources/Icons/XamlIconResource.cs @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * 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/. + */ + +using System; + +namespace SafeExamBrowser.Applications.Contracts.Resources.Icons +{ + /// + /// Defines an icon resource which consists of XAML markup (i.e. vector graphics). + /// + public class XamlIconResource : IconResource + { + /// + /// The pointing to the XAML file. + /// + public Uri Uri { get; set; } + } +} diff --git a/SafeExamBrowser.Applications.Contracts/SafeExamBrowser.Applications.Contracts.csproj b/SafeExamBrowser.Applications.Contracts/SafeExamBrowser.Applications.Contracts.csproj index 09a77d78..5af534be 100644 --- a/SafeExamBrowser.Applications.Contracts/SafeExamBrowser.Applications.Contracts.csproj +++ b/SafeExamBrowser.Applications.Contracts/SafeExamBrowser.Applications.Contracts.csproj @@ -61,13 +61,14 @@ + + + + + - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts - {30b2d907-5861-4f39-abad-c4abf1b3470e} SafeExamBrowser.Settings diff --git a/SafeExamBrowser.Applications/ExternalApplication.cs b/SafeExamBrowser.Applications/ExternalApplication.cs index 33ccd63b..fc72d452 100644 --- a/SafeExamBrowser.Applications/ExternalApplication.cs +++ b/SafeExamBrowser.Applications/ExternalApplication.cs @@ -11,7 +11,7 @@ using System.Collections.Generic; using System.Linq; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts.Events; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Monitoring.Contracts.Applications; using SafeExamBrowser.Settings.Applications; @@ -67,7 +67,7 @@ namespace SafeExamBrowser.Applications public void Initialize() { AutoStart = settings.AutoStart; - Icon = new IconResource { Type = IconResourceType.Embedded, Uri = new Uri(executablePath) }; + Icon = new EmbeddedIconResource { FilePath = executablePath }; Id = settings.Id; Name = settings.DisplayName; Tooltip = settings.Description ?? settings.DisplayName; diff --git a/SafeExamBrowser.Applications/ExternalApplicationInstance.cs b/SafeExamBrowser.Applications/ExternalApplicationInstance.cs index 2bd3ed2c..d3797ff0 100644 --- a/SafeExamBrowser.Applications/ExternalApplicationInstance.cs +++ b/SafeExamBrowser.Applications/ExternalApplicationInstance.cs @@ -12,8 +12,8 @@ using System.Linq; using System.Timers; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts.Events; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.Applications.Events; -using SafeExamBrowser.Core.Contracts; using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.WindowsApi.Contracts; diff --git a/SafeExamBrowser.Applications/ExternalApplicationWindow.cs b/SafeExamBrowser.Applications/ExternalApplicationWindow.cs index b5194bb3..13489c98 100644 --- a/SafeExamBrowser.Applications/ExternalApplicationWindow.cs +++ b/SafeExamBrowser.Applications/ExternalApplicationWindow.cs @@ -9,7 +9,7 @@ using System; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts.Events; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.WindowsApi.Contracts; namespace SafeExamBrowser.Applications @@ -19,10 +19,10 @@ namespace SafeExamBrowser.Applications private INativeMethods nativeMethods; internal IntPtr Handle { get; } - public IconResource Icon { get; } + public IconResource Icon { get; private set; } public string Title { get; private set; } - public event IconChangedEventHandler IconChanged { add { } remove { } } + public event IconChangedEventHandler IconChanged; public event TitleChangedEventHandler TitleChanged; internal ExternalApplicationWindow(IconResource icon, INativeMethods nativeMethods, IntPtr handle) @@ -39,10 +39,18 @@ namespace SafeExamBrowser.Applications internal void Update() { + var icon = nativeMethods.GetWindowIcon(Handle); + var iconChanged = icon != IntPtr.Zero && (!(Icon is NativeIconResource) || Icon is NativeIconResource r && r.Handle != icon); var title = nativeMethods.GetWindowTitle(Handle); - var hasChanged = Title?.Equals(title, StringComparison.Ordinal) != true; + var titleChanged = Title?.Equals(title, StringComparison.Ordinal) != true; - if (hasChanged) + if (iconChanged) + { + Icon = new NativeIconResource { Handle = icon }; + IconChanged?.Invoke(Icon); + } + + if (titleChanged) { Title = title; TitleChanged?.Invoke(title); diff --git a/SafeExamBrowser.Applications/SafeExamBrowser.Applications.csproj b/SafeExamBrowser.Applications/SafeExamBrowser.Applications.csproj index 1c748536..f35e7e91 100644 --- a/SafeExamBrowser.Applications/SafeExamBrowser.Applications.csproj +++ b/SafeExamBrowser.Applications/SafeExamBrowser.Applications.csproj @@ -66,10 +66,6 @@ {ac77745d-3b41-43e2-8e84-d40e5a4ee77f} SafeExamBrowser.Applications.Contracts - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts - {64ea30fb-11d4-436a-9c2b-88566285363e} SafeExamBrowser.Logging.Contracts diff --git a/SafeExamBrowser.Browser/BrowserApplication.cs b/SafeExamBrowser.Browser/BrowserApplication.cs index cd48c69e..6dd8f3b9 100644 --- a/SafeExamBrowser.Browser/BrowserApplication.cs +++ b/SafeExamBrowser.Browser/BrowserApplication.cs @@ -13,11 +13,11 @@ using CefSharp; using CefSharp.WinForms; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts.Events; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.Browser.Contracts; using SafeExamBrowser.Browser.Contracts.Events; using SafeExamBrowser.Browser.Events; using SafeExamBrowser.Configuration.Contracts; -using SafeExamBrowser.Core.Contracts; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Settings.Logging; diff --git a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs index 74e2ed63..64aa7b90 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs @@ -11,13 +11,13 @@ using System.Net.Http; using System.Threading.Tasks; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts.Events; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.Browser.Contracts.Events; using SafeExamBrowser.Browser.Contracts.Filters; using SafeExamBrowser.Browser.Events; using SafeExamBrowser.Browser.Filters; using SafeExamBrowser.Browser.Handlers; using SafeExamBrowser.Configuration.Contracts; -using SafeExamBrowser.Core.Contracts; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Settings.Browser; diff --git a/SafeExamBrowser.Browser/BrowserIconResource.cs b/SafeExamBrowser.Browser/BrowserIconResource.cs index 61f16d88..9edadcc4 100644 --- a/SafeExamBrowser.Browser/BrowserIconResource.cs +++ b/SafeExamBrowser.Browser/BrowserIconResource.cs @@ -7,15 +7,14 @@ */ using System; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; namespace SafeExamBrowser.Browser { - public class BrowserIconResource : IconResource + public class BrowserIconResource : BitmapIconResource { public BrowserIconResource(string uri = null) { - Type = IconResourceType.Bitmap; Uri = new Uri(uri ?? "pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/SafeExamBrowser.ico"); } } diff --git a/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj b/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj index af07210f..877dec92 100644 --- a/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj +++ b/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj @@ -99,10 +99,6 @@ {7d74555e-63e1-4c46-bd0a-8580552368c8} SafeExamBrowser.Configuration.Contracts - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts - {1858ddf3-bc2a-4bff-b663-4ce2ffeb8b7d} SafeExamBrowser.I18n.Contracts diff --git a/SafeExamBrowser.Client.Contracts/INotificationInfo.cs b/SafeExamBrowser.Client.Contracts/INotificationInfo.cs index c6e1de79..613a033b 100644 --- a/SafeExamBrowser.Client.Contracts/INotificationInfo.cs +++ b/SafeExamBrowser.Client.Contracts/INotificationInfo.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; namespace SafeExamBrowser.Client.Contracts { diff --git a/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj b/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj index 2c49fd3b..d8d10dbe 100644 --- a/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj +++ b/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj @@ -60,6 +60,10 @@ + + {ac77745d-3b41-43e2-8e84-d40e5a4ee77f} + SafeExamBrowser.Applications.Contracts + {fe0e1224-b447-4b14-81e7-ed7d84822aa0} SafeExamBrowser.Core.Contracts diff --git a/SafeExamBrowser.Client/Notifications/AboutNotificationInfo.cs b/SafeExamBrowser.Client/Notifications/AboutNotificationInfo.cs index 5f50c675..9ba2a071 100644 --- a/SafeExamBrowser.Client/Notifications/AboutNotificationInfo.cs +++ b/SafeExamBrowser.Client/Notifications/AboutNotificationInfo.cs @@ -7,8 +7,8 @@ */ using System; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.Client.Contracts; -using SafeExamBrowser.Core.Contracts; using SafeExamBrowser.I18n.Contracts; namespace SafeExamBrowser.Client.Notifications @@ -20,11 +20,7 @@ namespace SafeExamBrowser.Client.Notifications public AboutNotificationInfo(IText text) { - IconResource = new IconResource - { - Type = IconResourceType.Xaml, - Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/AboutNotification.xaml") - }; + IconResource = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/AboutNotification.xaml") }; Tooltip = text.Get(TextKey.Notification_AboutTooltip); } } diff --git a/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs b/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs index dd7a9cd7..483ebaeb 100644 --- a/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs +++ b/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs @@ -7,8 +7,8 @@ */ using System; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.Client.Contracts; -using SafeExamBrowser.Core.Contracts; using SafeExamBrowser.I18n.Contracts; namespace SafeExamBrowser.Client.Notifications @@ -20,11 +20,7 @@ namespace SafeExamBrowser.Client.Notifications public LogNotificationInfo(IText text) { - IconResource = new IconResource - { - Type = IconResourceType.Bitmap, - Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/LogNotification.ico") - }; + IconResource = new BitmapIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/LogNotification.ico") }; Tooltip = text.Get(TextKey.Notification_LogTooltip); } } diff --git a/SafeExamBrowser.Core.Contracts/IconResourceType.cs b/SafeExamBrowser.Core.Contracts/IconResourceType.cs deleted file mode 100644 index 11a004aa..00000000 --- a/SafeExamBrowser.Core.Contracts/IconResourceType.cs +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * - * 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/. - */ - -namespace SafeExamBrowser.Core.Contracts -{ - /// - /// Defines the data format of an icon resource. - /// - public enum IconResourceType - { - /// - /// The icon resource is a bitmap image (i.e. raster graphics). - /// - Bitmap, - - /// - /// The icon resource is a file with embedded icon data (e.g. an executable). - /// - Embedded, - - /// - /// The icon resource consists of XAML markup (i.e. vector graphics). - /// - Xaml - } -} diff --git a/SafeExamBrowser.Core.Contracts/SafeExamBrowser.Core.Contracts.csproj b/SafeExamBrowser.Core.Contracts/SafeExamBrowser.Core.Contracts.csproj index 9cfe850e..20b14816 100644 --- a/SafeExamBrowser.Core.Contracts/SafeExamBrowser.Core.Contracts.csproj +++ b/SafeExamBrowser.Core.Contracts/SafeExamBrowser.Core.Contracts.csproj @@ -54,8 +54,6 @@ - - diff --git a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs index dda2c424..858ab9f0 100644 --- a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs +++ b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Contracts.Browser.Events; using SafeExamBrowser.UserInterface.Contracts.Windows; diff --git a/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj b/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj index 05e1c68a..ce89a3a0 100644 --- a/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj +++ b/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj @@ -103,10 +103,6 @@ {7d74555e-63e1-4c46-bd0a-8580552368c8} SafeExamBrowser.Configuration.Contracts - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts - {1858ddf3-bc2a-4bff-b663-4ce2ffeb8b7d} SafeExamBrowser.I18n.Contracts diff --git a/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs index 59f83a39..537a9e6e 100644 --- a/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/BrowserWindow.xaml.cs @@ -14,9 +14,9 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using SafeExamBrowser.Settings.Browser; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; +using SafeExamBrowser.Settings.Browser; using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser.Events; @@ -106,7 +106,13 @@ namespace SafeExamBrowser.UserInterface.Desktop public void UpdateIcon(IconResource icon) { - Dispatcher.InvokeAsync(() => Icon = new BitmapImage(icon.Uri)); + Dispatcher.InvokeAsync(() => + { + if (icon is BitmapIconResource bitmap) + { + Icon = new BitmapImage(bitmap.Uri); + } + }); } public void UpdateLoadingState(bool isLoading) @@ -278,14 +284,10 @@ namespace SafeExamBrowser.UserInterface.Desktop private void LoadIcons() { - var backUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateBack.xaml"); - var forwardUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateForward.xaml"); - var menuUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Menu.xaml"); - var reloadUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Reload.xaml"); - var backward = new IconResource { Type = IconResourceType.Xaml, Uri = backUri }; - var forward = new IconResource { Type = IconResourceType.Xaml, Uri = forwardUri }; - var menu = new IconResource { Type = IconResourceType.Xaml, Uri = menuUri }; - var reload = new IconResource { Type = IconResourceType.Xaml, Uri = reloadUri }; + var backward = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateBack.xaml") }; + var forward = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateForward.xaml") }; + var menu = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Menu.xaml") }; + var reload = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Reload.xaml") }; BackwardButton.Content = IconResourceLoader.Load(backward); ForwardButton.Content = IconResourceLoader.Load(forward); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterApplicationButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterApplicationButton.xaml.cs index 92226fff..de63f784 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterApplicationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterApplicationButton.xaml.cs @@ -9,7 +9,7 @@ using System; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Shared.Utilities; namespace SafeExamBrowser.UserInterface.Desktop.Controls @@ -32,7 +32,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls private void InitializeApplicationInstanceButton() { - Icon.Content = IconResourceLoader.Load(application.Icon); + Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon); Text.Text = window?.Title ?? application.Name; Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty); Button.ToolTip = window?.Title ?? application.Tooltip; diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterAudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterAudioControl.xaml.cs index d7ee7830..c6130c30 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterAudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterAudioControl.xaml.cs @@ -13,7 +13,7 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; using System.Windows.Threading; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.Audio; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -51,8 +51,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); MuteButton.Click += MuteButton_Click; - MutedIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Muted.xaml") }; - NoDeviceIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Light_NoDevice.xaml") }; + MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Muted.xaml") }; + NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Light_NoDevice.xaml") }; Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; Popup.Closed += (o, args) => Grid.Background = originalBrush; @@ -147,7 +147,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls { var icon = volume > 0.66 ? "100" : (volume > 0.33 ? "66" : "33"); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Light_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri}; + var resource = new XamlIconResource { Uri = uri}; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterQuitButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterQuitButton.xaml.cs index 3c43d031..55c8b4ee 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterQuitButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterQuitButton.xaml.cs @@ -9,7 +9,7 @@ using System; using System.ComponentModel; using System.Windows.Controls; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; using SafeExamBrowser.UserInterface.Shared.Utilities; @@ -28,7 +28,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls private void InitializeControl() { var uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/ShutDown.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; Icon.Content = IconResourceLoader.Load(resource); Button.Click += (o, args) => Clicked?.Invoke(new CancelEventArgs()); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterWirelessNetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterWirelessNetworkControl.xaml.cs index 60251f58..30570a95 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterWirelessNetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenterWirelessNetworkControl.xaml.cs @@ -12,7 +12,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using FontAwesome.WPF; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.WirelessNetwork; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -134,7 +134,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls { var icon = signalStrength > 66 ? "100" : (signalStrength > 33 ? "66" : (signalStrength > 0 ? "33" : "0")); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/WiFi_Light_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskViewWindowControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskViewWindowControl.xaml.cs index f8447021..34ad9fee 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskViewWindowControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskViewWindowControl.xaml.cs @@ -9,7 +9,7 @@ using System.Windows; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Shared.Utilities; namespace SafeExamBrowser.UserInterface.Desktop.Controls diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarApplicationWindowButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarApplicationWindowButton.xaml.cs index a10b3f6a..1b571a9a 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarApplicationWindowButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarApplicationWindowButton.xaml.cs @@ -9,7 +9,7 @@ using System.Windows; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Shared.Utilities; namespace SafeExamBrowser.UserInterface.Desktop.Controls diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarAudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarAudioControl.xaml.cs index 3435f8d5..7e87b914 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarAudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarAudioControl.xaml.cs @@ -12,7 +12,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.Audio; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -50,8 +50,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); MuteButton.Click += MuteButton_Click; - MutedIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Muted.xaml") }; - NoDeviceIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_NoDevice.xaml") }; + MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Muted.xaml") }; + NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_NoDevice.xaml") }; Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Volume.ValueChanged += Volume_ValueChanged; @@ -154,7 +154,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls { var icon = volume > 0.66 ? "100" : (volume > 0.33 ? "66" : "33"); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarQuitButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarQuitButton.xaml.cs index 1067e0c1..97143bc1 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarQuitButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarQuitButton.xaml.cs @@ -10,7 +10,7 @@ using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; using SafeExamBrowser.UserInterface.Shared.Utilities; @@ -34,7 +34,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls private void LoadIcon() { var uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/ShutDown.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; Button.Content = IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarWirelessNetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarWirelessNetworkControl.xaml.cs index b32549af..98f6ad05 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarWirelessNetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/TaskbarWirelessNetworkControl.xaml.cs @@ -12,7 +12,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using FontAwesome.WPF; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.WirelessNetwork; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -143,7 +143,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls { var icon = signalStrength > 66 ? "100" : (signalStrength > 33 ? "66" : (signalStrength > 0 ? "33" : "0")); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/WiFi_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Desktop/SafeExamBrowser.UserInterface.Desktop.csproj b/SafeExamBrowser.UserInterface.Desktop/SafeExamBrowser.UserInterface.Desktop.csproj index e8a13618..f5b2bb3d 100644 --- a/SafeExamBrowser.UserInterface.Desktop/SafeExamBrowser.UserInterface.Desktop.csproj +++ b/SafeExamBrowser.UserInterface.Desktop/SafeExamBrowser.UserInterface.Desktop.csproj @@ -451,10 +451,6 @@ {7d74555e-63e1-4c46-bd0a-8580552368c8} SafeExamBrowser.Configuration.Contracts - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts - {1858ddf3-bc2a-4bff-b663-4ce2ffeb8b7d} SafeExamBrowser.I18n.Contracts diff --git a/SafeExamBrowser.UserInterface.Mobile/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/BrowserWindow.xaml.cs index 3283080c..f8c282ed 100644 --- a/SafeExamBrowser.UserInterface.Mobile/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/BrowserWindow.xaml.cs @@ -14,9 +14,9 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using SafeExamBrowser.Settings.Browser; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; +using SafeExamBrowser.Settings.Browser; using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser.Events; @@ -106,7 +106,13 @@ namespace SafeExamBrowser.UserInterface.Mobile public void UpdateIcon(IconResource icon) { - Dispatcher.InvokeAsync(() => Icon = new BitmapImage(icon.Uri)); + Dispatcher.InvokeAsync(() => + { + if (icon is BitmapIconResource bitmap) + { + Icon = new BitmapImage(bitmap.Uri); + } + }); } public void UpdateLoadingState(bool isLoading) @@ -287,14 +293,10 @@ namespace SafeExamBrowser.UserInterface.Mobile private void LoadIcons() { - var backUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateBack.xaml"); - var forwardUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateForward.xaml"); - var menuUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Menu.xaml"); - var reloadUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Reload.xaml"); - var backward = new IconResource { Type = IconResourceType.Xaml, Uri = backUri }; - var forward = new IconResource { Type = IconResourceType.Xaml, Uri = forwardUri }; - var menu = new IconResource { Type = IconResourceType.Xaml, Uri = menuUri }; - var reload = new IconResource { Type = IconResourceType.Xaml, Uri = reloadUri }; + var backward = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateBack.xaml") }; + var forward = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateForward.xaml") }; + var menu = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Menu.xaml") }; + var reload = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Reload.xaml") }; BackwardButton.Content = IconResourceLoader.Load(backward); ForwardButton.Content = IconResourceLoader.Load(forward); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterApplicationButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterApplicationButton.xaml.cs index b2c581f7..d9a144b7 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterApplicationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterApplicationButton.xaml.cs @@ -9,7 +9,7 @@ using System; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Shared.Utilities; namespace SafeExamBrowser.UserInterface.Mobile.Controls @@ -32,7 +32,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls private void InitializeApplicationInstanceButton() { - Icon.Content = IconResourceLoader.Load(application.Icon); + Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon); Text.Text = window?.Title ?? application.Name; Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty); Button.ToolTip = window?.Title ?? application.Tooltip; diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterAudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterAudioControl.xaml.cs index 385babb1..f0a36ac4 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterAudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterAudioControl.xaml.cs @@ -13,7 +13,7 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; using System.Windows.Threading; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.Audio; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -51,8 +51,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); MuteButton.Click += MuteButton_Click; - MutedIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Muted.xaml") }; - NoDeviceIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Light_NoDevice.xaml") }; + MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Muted.xaml") }; + NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Light_NoDevice.xaml") }; Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; Popup.Closed += (o, args) => Grid.Background = originalBrush; @@ -146,7 +146,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls { var icon = volume > 0.66 ? "100" : (volume > 0.33 ? "66" : "33"); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Light_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterQuitButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterQuitButton.xaml.cs index faa45d05..8f088ec0 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterQuitButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterQuitButton.xaml.cs @@ -9,7 +9,7 @@ using System; using System.ComponentModel; using System.Windows.Controls; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; using SafeExamBrowser.UserInterface.Shared.Utilities; @@ -28,7 +28,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls private void InitializeControl() { var uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/ShutDown.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; Icon.Content = IconResourceLoader.Load(resource); Button.Click += (o, args) => Clicked?.Invoke(new CancelEventArgs()); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterWirelessNetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterWirelessNetworkControl.xaml.cs index 99f2b65c..a989dca9 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterWirelessNetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenterWirelessNetworkControl.xaml.cs @@ -12,7 +12,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using FontAwesome.WPF; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.WirelessNetwork; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -134,7 +134,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls { var icon = signalStrength > 66 ? "100" : (signalStrength > 33 ? "66" : (signalStrength > 0 ? "33" : "0")); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/WiFi_Light_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskViewWindowControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskViewWindowControl.xaml.cs index 94ec2602..b039b8c1 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskViewWindowControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskViewWindowControl.xaml.cs @@ -9,7 +9,7 @@ using System.Windows; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Shared.Utilities; namespace SafeExamBrowser.UserInterface.Mobile.Controls diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarApplicationWindowButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarApplicationWindowButton.xaml.cs index b5bc9ca4..07f1ad80 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarApplicationWindowButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarApplicationWindowButton.xaml.cs @@ -9,7 +9,7 @@ using System.Windows; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Shared.Utilities; namespace SafeExamBrowser.UserInterface.Mobile.Controls diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarAudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarAudioControl.xaml.cs index 6907412c..eefb28a4 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarAudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarAudioControl.xaml.cs @@ -12,7 +12,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.Audio; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -50,8 +50,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); MuteButton.Click += MuteButton_Click; - MutedIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Muted.xaml") }; - NoDeviceIcon = new IconResource { Type = IconResourceType.Xaml, Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_NoDevice.xaml") }; + MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Muted.xaml") }; + NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_NoDevice.xaml") }; Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Volume.ValueChanged += Volume_ValueChanged; @@ -154,7 +154,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls { var icon = volume > 0.66 ? "100" : (volume > 0.33 ? "66" : "33"); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarQuitButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarQuitButton.xaml.cs index ddf99ff0..2e74ca8d 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarQuitButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarQuitButton.xaml.cs @@ -10,7 +10,7 @@ using System; using System.ComponentModel; using System.Windows; using System.Windows.Controls; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; using SafeExamBrowser.UserInterface.Shared.Utilities; @@ -34,7 +34,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls private void LoadIcon() { var uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/ShutDown.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; Button.Content = IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarWirelessNetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarWirelessNetworkControl.xaml.cs index 8d6267e9..6a44cb23 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarWirelessNetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/TaskbarWirelessNetworkControl.xaml.cs @@ -12,7 +12,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using FontAwesome.WPF; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.SystemComponents.Contracts.WirelessNetwork; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -143,7 +143,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls { var icon = signalStrength > 66 ? "100" : (signalStrength > 33 ? "66" : (signalStrength > 0 ? "33" : "0")); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/WiFi_{icon}.xaml"); - var resource = new IconResource { Type = IconResourceType.Xaml, Uri = uri }; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj b/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj index 8e7cee3f..5db927d4 100644 --- a/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj +++ b/SafeExamBrowser.UserInterface.Mobile/SafeExamBrowser.UserInterface.Mobile.csproj @@ -193,10 +193,6 @@ {7d74555e-63e1-4c46-bd0a-8580552368c8} SafeExamBrowser.Configuration.Contracts - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts - {1858ddf3-bc2a-4bff-b663-4ce2ffeb8b7d} SafeExamBrowser.I18n.Contracts diff --git a/SafeExamBrowser.UserInterface.Shared/SafeExamBrowser.UserInterface.Shared.csproj b/SafeExamBrowser.UserInterface.Shared/SafeExamBrowser.UserInterface.Shared.csproj index 04c90897..92e0291e 100644 --- a/SafeExamBrowser.UserInterface.Shared/SafeExamBrowser.UserInterface.Shared.csproj +++ b/SafeExamBrowser.UserInterface.Shared/SafeExamBrowser.UserInterface.Shared.csproj @@ -77,9 +77,9 @@ - - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} - SafeExamBrowser.Core.Contracts + + {ac77745d-3b41-43e2-8e84-d40e5a4ee77f} + SafeExamBrowser.Applications.Contracts {64ea30fb-11d4-436a-9c2b-88566285363e} diff --git a/SafeExamBrowser.UserInterface.Shared/Utilities/IconResourceLoader.cs b/SafeExamBrowser.UserInterface.Shared/Utilities/IconResourceLoader.cs index 475dff51..fb237688 100644 --- a/SafeExamBrowser.UserInterface.Shared/Utilities/IconResourceLoader.cs +++ b/SafeExamBrowser.UserInterface.Shared/Utilities/IconResourceLoader.cs @@ -13,9 +13,10 @@ using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; +using System.Windows.Interop; using System.Windows.Markup; using System.Windows.Media.Imaging; -using SafeExamBrowser.Core.Contracts; +using SafeExamBrowser.Applications.Contracts.Resources.Icons; using Brushes = System.Windows.Media.Brushes; using Image = System.Windows.Controls.Image; @@ -27,16 +28,18 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities { try { - switch (resource.Type) + switch (resource) { - case IconResourceType.Bitmap: - return LoadBitmapResource(resource); - case IconResourceType.Embedded: - return LoadEmbeddedResource(resource); - case IconResourceType.Xaml: - return LoadXamlResource(resource); + case BitmapIconResource bitmap: + return LoadBitmapResource(bitmap); + case EmbeddedIconResource embedded: + return LoadEmbeddedResource(embedded); + case NativeIconResource native: + return LoadNativeResource(native); + case XamlIconResource xaml: + return LoadXamlResource(xaml); default: - throw new NotSupportedException($"Application icon resource of type '{resource.Type}' is not supported!"); + throw new NotSupportedException($"Application icon resource of type '{resource.GetType()}' is not supported!"); } } catch (Exception) @@ -45,7 +48,7 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities } } - private static UIElement LoadBitmapResource(IconResource resource) + private static UIElement LoadBitmapResource(BitmapIconResource resource) { return new Image { @@ -53,13 +56,13 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities }; } - private static UIElement LoadEmbeddedResource(IconResource resource) + private static UIElement LoadEmbeddedResource(EmbeddedIconResource resource) { using (var stream = new MemoryStream()) { var bitmap = new BitmapImage(); - Icon.ExtractAssociatedIcon(resource.Uri.LocalPath).ToBitmap().Save(stream, ImageFormat.Png); + Icon.ExtractAssociatedIcon(resource.FilePath).ToBitmap().Save(stream, ImageFormat.Png); bitmap.BeginInit(); bitmap.StreamSource = stream; @@ -74,7 +77,15 @@ namespace SafeExamBrowser.UserInterface.Shared.Utilities } } - private static UIElement LoadXamlResource(IconResource resource) + private static UIElement LoadNativeResource(NativeIconResource resource) + { + return new Image + { + Source = Imaging.CreateBitmapSourceFromHIcon(resource.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()) + }; + } + + private static UIElement LoadXamlResource(XamlIconResource resource) { using (var stream = Application.GetResourceStream(resource.Uri)?.Stream) { diff --git a/SafeExamBrowser.WindowsApi.Contracts/INativeMethods.cs b/SafeExamBrowser.WindowsApi.Contracts/INativeMethods.cs index 6ed3e422..1c16ed1c 100644 --- a/SafeExamBrowser.WindowsApi.Contracts/INativeMethods.cs +++ b/SafeExamBrowser.WindowsApi.Contracts/INativeMethods.cs @@ -90,6 +90,11 @@ namespace SafeExamBrowser.WindowsApi.Contracts /// string GetWallpaperPath(); + /// + /// Attempts to retrieve the icon of the given window. Returns a handle to the icon, or if the icon could not be retrieved. + /// + IntPtr GetWindowIcon(IntPtr window); + /// /// Retrieves the title of the window with the given handle, or an empty string if the given window does not have a title. /// diff --git a/SafeExamBrowser.WindowsApi/Constants/Constant.cs b/SafeExamBrowser.WindowsApi/Constants/Constant.cs index 30afdb97..d05bfa2b 100644 --- a/SafeExamBrowser.WindowsApi/Constants/Constant.cs +++ b/SafeExamBrowser.WindowsApi/Constants/Constant.cs @@ -27,6 +27,22 @@ namespace SafeExamBrowser.WindowsApi.Constants /// internal const uint EVENT_SYSTEM_FOREGROUND = 0x3; + /// + /// The large icon of a window. See https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-geticon#parameters. + /// + internal const int ICON_BIG = 1; + + /// + /// The small icon of a window. See https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-geticon#parameters. + /// + internal const int ICON_SMALL = 0; + + /// + /// The small icon of an application. If an application does not provide one, the system uses a system-generated icon for a window. + /// See https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-geticon#parameters. + /// + internal const int ICON_SMALL2 = 2; + /// /// Minimize all open windows. /// @@ -84,6 +100,14 @@ namespace SafeExamBrowser.WindowsApi.Constants /// internal const int WM_COMMAND = 0x111; + /// + /// Sent to a window to retrieve a handle to the large or small icon associated with a window. The system displays the large icon + /// in the ALT+TAB dialog, and the small icon in the window caption. + /// + /// See https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-geticon. + /// + internal const int WM_GETICON = 0x7F; + /// /// Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when /// the ALT key is not pressed. diff --git a/SafeExamBrowser.WindowsApi/NativeMethods.cs b/SafeExamBrowser.WindowsApi/NativeMethods.cs index c84ab429..fa489c9a 100644 --- a/SafeExamBrowser.WindowsApi/NativeMethods.cs +++ b/SafeExamBrowser.WindowsApi/NativeMethods.cs @@ -199,6 +199,23 @@ namespace SafeExamBrowser.WindowsApi return path; } + public IntPtr GetWindowIcon(IntPtr window) + { + var icon = User32.SendMessage(window, Constant.WM_GETICON, new IntPtr(Constant.ICON_BIG), IntPtr.Zero); + + if (icon == IntPtr.Zero) + { + icon = User32.SendMessage(window, Constant.WM_GETICON, new IntPtr(Constant.ICON_SMALL), IntPtr.Zero); + } + + if (icon == IntPtr.Zero) + { + icon = User32.SendMessage(window, Constant.WM_GETICON, new IntPtr(Constant.ICON_SMALL2), IntPtr.Zero); + } + + return icon; + } + public string GetWindowTitle(IntPtr window) { var length = User32.GetWindowTextLength(window);