2019-11-29 14:59:54 +01:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2019-11-29 14:59:54 +01: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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using SafeExamBrowser.Applications.Contracts;
|
|
|
|
|
using SafeExamBrowser.Applications.Contracts.Events;
|
2021-03-18 23:12:07 +01:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.Resources.Icons;
|
2019-11-29 14:59:54 +01:00
|
|
|
|
using SafeExamBrowser.WindowsApi.Contracts;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Applications
|
|
|
|
|
{
|
|
|
|
|
internal class ExternalApplicationWindow : IApplicationWindow
|
|
|
|
|
{
|
2023-06-01 18:18:01 +02:00
|
|
|
|
private readonly INativeMethods nativeMethods;
|
2019-11-29 14:59:54 +01:00
|
|
|
|
|
2019-12-05 11:54:43 +01:00
|
|
|
|
public IntPtr Handle { get; }
|
2019-12-03 15:43:48 +01:00
|
|
|
|
public IconResource Icon { get; private set; }
|
2019-11-29 14:59:54 +01:00
|
|
|
|
public string Title { get; private set; }
|
|
|
|
|
|
2019-12-03 15:43:48 +01:00
|
|
|
|
public event IconChangedEventHandler IconChanged;
|
2019-11-29 14:59:54 +01:00
|
|
|
|
public event TitleChangedEventHandler TitleChanged;
|
|
|
|
|
|
|
|
|
|
internal ExternalApplicationWindow(IconResource icon, INativeMethods nativeMethods, IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
this.Handle = handle;
|
|
|
|
|
this.Icon = icon;
|
|
|
|
|
this.nativeMethods = nativeMethods;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Activate()
|
|
|
|
|
{
|
|
|
|
|
nativeMethods.ActivateWindow(Handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Update()
|
|
|
|
|
{
|
2019-12-03 15:43:48 +01:00
|
|
|
|
var icon = nativeMethods.GetWindowIcon(Handle);
|
|
|
|
|
var iconChanged = icon != IntPtr.Zero && (!(Icon is NativeIconResource) || Icon is NativeIconResource r && r.Handle != icon);
|
2019-11-29 14:59:54 +01:00
|
|
|
|
var title = nativeMethods.GetWindowTitle(Handle);
|
2019-12-03 15:43:48 +01:00
|
|
|
|
var titleChanged = Title?.Equals(title, StringComparison.Ordinal) != true;
|
2019-11-29 14:59:54 +01:00
|
|
|
|
|
2019-12-03 15:43:48 +01:00
|
|
|
|
if (iconChanged)
|
|
|
|
|
{
|
|
|
|
|
Icon = new NativeIconResource { Handle = icon };
|
|
|
|
|
IconChanged?.Invoke(Icon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (titleChanged)
|
2019-11-29 14:59:54 +01:00
|
|
|
|
{
|
|
|
|
|
Title = title;
|
|
|
|
|
TitleChanged?.Invoke(title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|