Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Files.App.CsWin32/Extras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Windows.Win32.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;

Expand Down Expand Up @@ -37,4 +38,14 @@ public static unsafe nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nInd
: _SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong);
}
}

namespace Extras
{
[GeneratedComInterface, Guid("EACDD04C-117E-4E17-88F4-D1B12B0E3D89"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public partial interface IDCompositionTarget
{
[PreserveSig]
int SetRoot(nint visual);
}
}
}
5 changes: 2 additions & 3 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ HWND
LRESULT
WPARAM
LPARAM
WM_LBUTTONUP
WM_RBUTTONUP
WM_DESTROY
WM_*
SetForegroundWindow
GetForegroundWindow
GetCurrentThreadId
Expand Down Expand Up @@ -173,3 +171,4 @@ FSCTL_LOCK_VOLUME
FILE_FILE_COMPRESSION
WM_WINDOWPOSCHANGING
WINDOWPOS
UnregisterClass
23 changes: 14 additions & 9 deletions src/Files.App/UserControls/FilePreviews/ShellPreview.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.ViewModels.Previews;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Vanara.PInvoke;
using Windows.Foundation;
using Windows.Win32.Foundation;

namespace Files.App.UserControls.FilePreviews
{
Expand All @@ -13,13 +16,15 @@ public sealed partial class ShellPreview : UserControl
public ShellPreview(ShellPreviewViewModel model)
{
ViewModel = model;
this.InitializeComponent();

InitializeComponent();
}

private void PreviewHost_Loaded(object sender, RoutedEventArgs e)
{
ViewModel.LoadPreview(contentPresenter);
ViewModel.SizeChanged(GetPreviewSize());

if (XamlRoot.Content is FrameworkElement element)
{
element.SizeChanged += PreviewHost_SizeChanged;
Expand All @@ -38,13 +43,12 @@ private RECT GetPreviewSize()
var physicalSize = contentPresenter.RenderSize;
var physicalPos = source.TransformPoint(new Point(0, 0));
var scale = XamlRoot.RasterizationScale;
var result = new RECT
{
X = (int)(physicalPos.X * scale + 0.5),
Y = (int)(physicalPos.Y * scale + 0.5),
Width = (int)(physicalSize.Width * scale + 0.5),
Height = (int)(physicalSize.Height * scale + 0.5)
};
var result = RECT.FromXYWH(
(int)(physicalPos.X * scale + 0.5),
(int)(physicalPos.Y * scale + 0.5),
(int)(physicalSize.Width * scale + 0.5),
(int)(physicalSize.Height * scale + 0.5));

return result;
}

Expand All @@ -55,6 +59,7 @@ private void PreviewHost_Unloaded(object sender, RoutedEventArgs e)
element.SizeChanged -= PreviewHost_SizeChanged;
element.PointerEntered -= PreviewHost_PointerEntered;
}

ViewModel.UnloadPreview();
}

Expand Down
Loading