Skip to content

Commit 449f1dc

Browse files
committed
Initial commit
1 parent 383d82c commit 449f1dc

File tree

5 files changed

+180
-138
lines changed

5 files changed

+180
-138
lines changed

src/Files.App.CsWin32/NativeMethods.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ HWND
2828
LRESULT
2929
WPARAM
3030
LPARAM
31-
WM_LBUTTONUP
32-
WM_RBUTTONUP
33-
WM_DESTROY
31+
WM_*
3432
SetForegroundWindow
3533
GetForegroundWindow
3634
GetCurrentThreadId
@@ -173,3 +171,4 @@ FSCTL_LOCK_VOLUME
173171
FILE_FILE_COMPRESSION
174172
WM_WINDOWPOSCHANGING
175173
WINDOWPOS
174+
UnregisterClass

src/Files.App.CsWin32/Windows.Win32.ComPtr.cs

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public ComPtr(T* ptr)
2727
((IUnknown*)ptr)->AddRef();
2828
}
2929

30+
public void Attach(T* other)
31+
{
32+
if (_ptr is not null)
33+
((IUnknown*)_ptr)->Release();
34+
35+
_ptr = other;
36+
}
37+
3038
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3139
public readonly T* Get()
3240
{

src/Files.App.CsWin32/Windows.Win32.Extras.cs

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System.Runtime.InteropServices;
5+
using System.Runtime.InteropServices.Marshalling;
56
using Windows.Win32.Foundation;
67
using Windows.Win32.UI.WindowsAndMessaging;
78

@@ -37,4 +38,14 @@ public static unsafe nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nInd
3738
: _SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong);
3839
}
3940
}
41+
42+
namespace Extras
43+
{
44+
[GeneratedComInterface, Guid("EACDD04C-117E-4E17-88F4-D1B12B0E3D89"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
45+
public partial interface IDCompositionTarget
46+
{
47+
[PreserveSig]
48+
int SetRoot(nint visual);
49+
}
50+
}
4051
}

src/Files.App/UserControls/FilePreviews/ShellPreview.xaml.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
14
using Files.App.ViewModels.Previews;
25
using Microsoft.UI.Xaml;
36
using Microsoft.UI.Xaml.Controls;
4-
using Vanara.PInvoke;
57
using Windows.Foundation;
8+
using Windows.Win32.Foundation;
69

710
namespace Files.App.UserControls.FilePreviews
811
{
@@ -13,13 +16,15 @@ public sealed partial class ShellPreview : UserControl
1316
public ShellPreview(ShellPreviewViewModel model)
1417
{
1518
ViewModel = model;
16-
this.InitializeComponent();
19+
20+
InitializeComponent();
1721
}
1822

1923
private void PreviewHost_Loaded(object sender, RoutedEventArgs e)
2024
{
2125
ViewModel.LoadPreview(contentPresenter);
2226
ViewModel.SizeChanged(GetPreviewSize());
27+
2328
if (XamlRoot.Content is FrameworkElement element)
2429
{
2530
element.SizeChanged += PreviewHost_SizeChanged;
@@ -38,13 +43,12 @@ private RECT GetPreviewSize()
3843
var physicalSize = contentPresenter.RenderSize;
3944
var physicalPos = source.TransformPoint(new Point(0, 0));
4045
var scale = XamlRoot.RasterizationScale;
41-
var result = new RECT
42-
{
43-
X = (int)(physicalPos.X * scale + 0.5),
44-
Y = (int)(physicalPos.Y * scale + 0.5),
45-
Width = (int)(physicalSize.Width * scale + 0.5),
46-
Height = (int)(physicalSize.Height * scale + 0.5)
47-
};
46+
var result = RECT.FromXYWH(
47+
(int)(physicalPos.X * scale + 0.5),
48+
(int)(physicalPos.Y * scale + 0.5),
49+
(int)(physicalSize.Width * scale + 0.5),
50+
(int)(physicalSize.Height * scale + 0.5));
51+
4852
return result;
4953
}
5054

@@ -55,6 +59,7 @@ private void PreviewHost_Unloaded(object sender, RoutedEventArgs e)
5559
element.SizeChanged -= PreviewHost_SizeChanged;
5660
element.PointerEntered -= PreviewHost_PointerEntered;
5761
}
62+
5863
ViewModel.UnloadPreview();
5964
}
6065

0 commit comments

Comments
 (0)