Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Sep 24, 2024
1 parent 99b8408 commit a42e03b
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 143 deletions.
14 changes: 14 additions & 0 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,17 @@ IFileOperation
IShellItem2
PSGetPropertyKeyFromName
ShellExecuteEx
E_FAIL
S_OK
S_FALSE
MSG
E_NOTIMPL
LOGFONTW
AssocCreate
IQueryAssociations
UnregisterClass
SetWindowLong
GetModuleHandle
RegisterClassEx
CREATESTRUCTW
AssocQueryString
22 changes: 15 additions & 7 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) 2024 Files Community
// Licensed under the MIT License. See the 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,11 +43,13 @@ private RECT GetPreviewSize()
var physicalSize = contentPresenter.RenderSize;
var physicalPos = source.TransformPoint(new Point(0, 0));
var scale = XamlRoot.RasterizationScale;
var result = new RECT();
result.Left = (int)(physicalPos.X * scale + 0.5);
result.Top = (int)(physicalPos.Y * scale + 0.5);
result.Width = (int)(physicalSize.Width * scale + 0.5);
result.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 @@ -53,6 +60,7 @@ private void PreviewHost_Unloaded(object sender, RoutedEventArgs e)
element.SizeChanged -= PreviewHost_SizeChanged;
element.PointerEntered -= PreviewHost_PointerEntered;
}

ViewModel.UnloadPreview();
}

Expand Down
Loading

0 comments on commit a42e03b

Please sign in to comment.