Skip to content

Code Quality: Replaced private const & struct with CsWin32 & Improve comments #16556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2024
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
2 changes: 2 additions & 0 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ IApplicationDocumentLists
ApplicationDocumentLists
IApplicationActivationManager
MENU_ITEM_TYPE
WM_WINDOWPOSCHANGING
WINDOWPOS
46 changes: 0 additions & 46 deletions src/Files.App.CsWin32/Windows.Win32.Extras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,5 @@ namespace UI.WindowsAndMessaging
{
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate LRESULT WNDPROC(HWND hWnd, uint msg, WPARAM wParam, LPARAM lParam);

/// <summary>Contains information about the size and position of a window.</summary>
/// <remarks>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos">Learn more about this API from docs.microsoft.com</see>.</para>
/// </remarks>
public partial struct WINDOWPOS
{
/// <summary>
/// <para>Type: <b>HWND</b> A handle to the window.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal HWND hwnd;

/// <summary>
/// <para>Type: <b>HWND</b> The position of the window in Z order (front-to-back position). This member can be a handle to the window behind which this window is placed, or can be one of the special values listed with the <a href="https://docs.microsoft.com/windows/desktop/api/winuser/nf-winuser-setwindowpos">SetWindowPos</a> function.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal HWND hwndInsertAfter;

/// <summary>
/// <para>Type: <b>int</b> The position of the left edge of the window.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal int x;

/// <summary>
/// <para>Type: <b>int</b> The position of the top edge of the window.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal int y;

/// <summary>
/// <para>Type: <b>int</b> The window width, in pixels.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal int cx;

/// <summary>
/// <para>Type: <b>int</b> The window height, in pixels.</para>
/// <para><see href="https://learn.microsoft.com/windows/win32/api/winuser/ns-winuser-windowpos#members">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal int cy;

/// <summary>Type: <b>UINT</b></summary>
public SET_WINDOW_POS_FLAGS flags;
}
}
}
3 changes: 1 addition & 2 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ public bool SetCanWindowToFront(bool canWindowToFront)
}
}

private const int WM_WINDOWPOSCHANGING = 0x0046;
private void WindowManager_WindowMessageReceived(object? sender, WinUIEx.Messaging.WindowMessageEventArgs e)
{
if ((!CanWindowToFront) && e.Message.MessageId == WM_WINDOWPOSCHANGING)
if ((!CanWindowToFront) && e.Message.MessageId == Windows.Win32.PInvoke.WM_WINDOWPOSCHANGING)
{
Win32Helper.ForceWindowPosition(e.Message.LParam);
e.Handled = true;
Expand Down
17 changes: 9 additions & 8 deletions src/Files.App/Views/Layouts/BaseLayoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti
e.Data.SetStorageItems(storageItemList, false);
}

// Set can window to front (#13255)
MainWindow.Instance.SetCanWindowToFront(false);
itemDragging = true;
}
Expand All @@ -1025,9 +1026,9 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti

protected virtual void FileList_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
{
// Set can window to front (#13255)
itemDragging = false;
MainWindow.Instance.SetCanWindowToFront(true);
// No need to bring the window to the front
}

private void Item_DragLeave(object sender, DragEventArgs e)
Expand Down Expand Up @@ -1159,9 +1160,9 @@ protected void FileList_ContainerContentChanging(ListViewBase sender, ContainerC
RefreshContainer(args.ItemContainer, args.InRecycleQueue);
RefreshItem(args.ItemContainer, args.Item, args.InRecycleQueue, args);

// Set can window to front (#13255)
itemDragging = false;
MainWindow.Instance.SetCanWindowToFront(true);
// No need to bring the window to the front
}

private void RefreshContainer(SelectorItem container, bool inRecycleQueue)
Expand Down Expand Up @@ -1216,7 +1217,7 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu

protected internal void FileListItem_PointerPressed(object sender, PointerRoutedEventArgs e)
{
// Set can window to front and bring the window to the front if necessary
// Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));

Expand Down Expand Up @@ -1245,7 +1246,7 @@ protected internal void FileListItem_PointerPressed(object sender, PointerRouted

protected internal void FileListItem_PointerEntered(object sender, PointerRoutedEventArgs e)
{
// Set can window to front before the item is dragged
// Set can window to front (#13255)
if (sender is SelectorItem selectorItem && selectorItem.IsSelected)
MainWindow.Instance.SetCanWindowToFront(false);

Expand Down Expand Up @@ -1295,7 +1296,7 @@ selectedItems is not null &&

protected internal void FileListItem_PointerExited(object sender, PointerRoutedEventArgs e)
{
// Set can window to front
// Set can window to front (#13255)
if (!itemDragging)
MainWindow.Instance.SetCanWindowToFront(true);

Expand All @@ -1308,21 +1309,21 @@ protected internal void FileListItem_PointerExited(object sender, PointerRoutedE

protected void FileListItem_Tapped(object sender, TappedRoutedEventArgs e)
{
// Set can window to front and bring the window to the front if necessary
// Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
}

protected void FileListItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
// Set can window to front and bring the window to the front if necessary
// Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
}

protected void FileListItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
// Set can window to front and bring the window to the front if necessary
// Set can window to front and bring the window to the front if necessary (#13255)
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));

Expand Down