Restore SEBPatch
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<UserControl x:Class="SafeExamBrowser.UserInterface.Desktop.Controls.Taskview.WindowControl" x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Desktop.Controls">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../../Templates/Colors.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="5" Height="175" Width="250">
|
||||
<Border Name="Indicator" Background="{StaticResource BackgroundTransparentEmphasisBrush}" BorderThickness="0" Visibility="Hidden" />
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<ContentControl Grid.Row="0" Grid.Column="0" Name="Icon" Margin="0,0,5,0" Height="16" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Name="Title" Foreground="{StaticResource PrimaryTextBrush}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
|
||||
<ContentControl Grid.Row="1" Grid.ColumnSpan="2" Name="Placeholder" Margin="0,5,0,0" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* 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 System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using SafeExamBrowser.Applications.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.Resources.Icons;
|
||||
using SafeExamBrowser.UserInterface.Shared.Utilities;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskview
|
||||
{
|
||||
internal partial class WindowControl : UserControl
|
||||
{
|
||||
private Windows.Taskview taskview;
|
||||
private IntPtr thumbnail;
|
||||
private IApplicationWindow window;
|
||||
|
||||
internal WindowControl(IApplicationWindow window, Windows.Taskview taskview)
|
||||
{
|
||||
this.window = window;
|
||||
this.taskview = taskview;
|
||||
|
||||
InitializeComponent();
|
||||
InitializeControl();
|
||||
}
|
||||
|
||||
internal void Activate()
|
||||
{
|
||||
window.Activate();
|
||||
}
|
||||
|
||||
internal void Deselect()
|
||||
{
|
||||
Indicator.Visibility = Visibility.Hidden;
|
||||
Title.FontWeight = FontWeights.Normal;
|
||||
}
|
||||
|
||||
internal void Destroy()
|
||||
{
|
||||
if (thumbnail != IntPtr.Zero)
|
||||
{
|
||||
Thumbnail.DwmUnregisterThumbnail(thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Select()
|
||||
{
|
||||
Indicator.Visibility = Visibility.Visible;
|
||||
Title.FontWeight = FontWeights.SemiBold;
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
if (!IsLoaded || !IsVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (thumbnail == IntPtr.Zero && taskview.Handle != IntPtr.Zero && window.Handle != IntPtr.Zero)
|
||||
{
|
||||
Thumbnail.DwmRegisterThumbnail(taskview.Handle, window.Handle, out thumbnail);
|
||||
}
|
||||
|
||||
if (thumbnail != IntPtr.Zero)
|
||||
{
|
||||
Thumbnail.DwmQueryThumbnailSourceSize(thumbnail, out var size);
|
||||
|
||||
var destination = CalculatePhysicalDestination(size);
|
||||
var properties = new Thumbnail.Properties
|
||||
{
|
||||
Destination = destination,
|
||||
Flags = Thumbnail.DWM_TNP_RECTDESTINATION | Thumbnail.DWM_TNP_VISIBLE,
|
||||
Visible = true
|
||||
};
|
||||
|
||||
Thumbnail.DwmUpdateThumbnailProperties(thumbnail, ref properties);
|
||||
}
|
||||
}
|
||||
|
||||
private void TaskViewWindowControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.NewValue as bool? == true)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_TitleChanged(string title)
|
||||
{
|
||||
Dispatcher.InvokeAsync(() => Title.Text = title);
|
||||
}
|
||||
|
||||
private void Window_IconChanged(IconResource icon)
|
||||
{
|
||||
Dispatcher.InvokeAsync(() => Icon.Content = IconResourceLoader.Load(window.Icon));
|
||||
}
|
||||
|
||||
private Thumbnail.Rectangle CalculatePhysicalDestination(Thumbnail.Size size)
|
||||
{
|
||||
var controlToTaskview = TransformToVisual(taskview);
|
||||
var placeholderToControl = Placeholder.TransformToVisual(this);
|
||||
var placeholderLeft = placeholderToControl.Transform(new Point(0, 0)).X;
|
||||
var placeholderTop = placeholderToControl.Transform(new Point(0, 0)).Y;
|
||||
var placeholderRight = placeholderToControl.Transform(new Point(Placeholder.ActualWidth, 0)).X;
|
||||
var placeholderBottom = placeholderToControl.Transform(new Point(0, Placeholder.ActualHeight)).Y;
|
||||
|
||||
var physicalBounds = new Thumbnail.Rectangle
|
||||
{
|
||||
Left = (int) Math.Round(this.TransformToPhysical(controlToTaskview.Transform(new Point(placeholderLeft, 0)).X, 0).X),
|
||||
Top = (int) Math.Round(this.TransformToPhysical(0, controlToTaskview.Transform(new Point(0, placeholderTop)).Y).Y),
|
||||
Right = (int) Math.Round(this.TransformToPhysical(controlToTaskview.Transform(new Point(placeholderRight, 0)).X, 0).X),
|
||||
Bottom = (int) Math.Round(this.TransformToPhysical(0, controlToTaskview.Transform(new Point(0, placeholderBottom)).Y).Y)
|
||||
};
|
||||
|
||||
var scaleFactor = default(double);
|
||||
var thumbnailHeight = default(double);
|
||||
var thumbnailWidth = default(double);
|
||||
var maxWidth = (double) physicalBounds.Right - physicalBounds.Left;
|
||||
var maxHeight = (double) physicalBounds.Bottom - physicalBounds.Top;
|
||||
var placeholderRatio = maxWidth / maxHeight;
|
||||
var windowRatio = (double) size.X / size.Y;
|
||||
|
||||
if (windowRatio < placeholderRatio)
|
||||
{
|
||||
thumbnailHeight = maxHeight;
|
||||
scaleFactor = thumbnailHeight / size.Y;
|
||||
thumbnailWidth = size.X * scaleFactor;
|
||||
}
|
||||
else
|
||||
{
|
||||
thumbnailWidth = maxWidth;
|
||||
scaleFactor = thumbnailWidth / size.X;
|
||||
thumbnailHeight = size.Y * scaleFactor;
|
||||
}
|
||||
|
||||
var widthDifference = maxWidth - thumbnailWidth;
|
||||
var heightDifference = maxHeight - thumbnailHeight;
|
||||
|
||||
return new Thumbnail.Rectangle
|
||||
{
|
||||
Left = (int) Math.Round(physicalBounds.Left + (widthDifference / 2)),
|
||||
Top = (int) Math.Round(physicalBounds.Top + (heightDifference / 2)),
|
||||
Right = (int) Math.Round(physicalBounds.Right - (widthDifference / 2)),
|
||||
Bottom = (int) Math.Round(physicalBounds.Bottom - (heightDifference / 2))
|
||||
};
|
||||
}
|
||||
|
||||
private void InitializeControl()
|
||||
{
|
||||
Icon.Content = IconResourceLoader.Load(window.Icon);
|
||||
IsVisibleChanged += TaskViewWindowControl_IsVisibleChanged;
|
||||
Loaded += (o, args) => Update();
|
||||
Title.Text = window.Title;
|
||||
window.IconChanged += Window_IconChanged;
|
||||
window.TitleChanged += Window_TitleChanged;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user