Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Aug 3, 2024
1 parent d0d6195 commit 1a67dc9
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 107 deletions.
14 changes: 14 additions & 0 deletions src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,17 @@ DesktopWallpaper
SHCreateShellItemArrayFromIDLists
ILCreateFromPath
CLSIDFromString
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 1a67dc9

Please sign in to comment.