From 754de9c2eee1e1c2b8ddd8ab9f186850fef500aa Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 21 May 2020 13:41:57 -0300 Subject: [PATCH] calculate extend metrics in function. --- .../Avalonia.Win32/WindowImpl.AppWndProc.cs | 2 +- src/Windows/Avalonia.Win32/WindowImpl.cs | 39 ++++--------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs index 0c2160de2b..5ffed48f2d 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs @@ -375,7 +375,7 @@ namespace Avalonia.Win32 { _lastWindowState = windowState; - UpdateExtendMargins(); + UpdateExtendMargins(_extendChromeHints); ExtendClientAreaToDecorationsChanged?.Invoke(true); diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 9891615a85..fd54365d7b 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -673,7 +673,7 @@ namespace Avalonia.Win32 TaskBarList.MarkFullscreen(_hwnd, fullscreen); } - private MARGINS UpdateExtendMargins() + private MARGINS UpdateExtendMargins(ExtendClientAreaChromeHints hints) { RECT borderThickness = new RECT(); RECT borderCaptionThickness = new RECT(); @@ -685,6 +685,11 @@ namespace Avalonia.Win32 borderCaptionThickness.left *= -1; borderCaptionThickness.top *= -1; + if (!hints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar)) + { + borderCaptionThickness.top = 1; + } + _extendedMargins = new Thickness(1 / Scaling, borderCaptionThickness.top / Scaling, 1 / Scaling, 1 / Scaling); if (WindowState == WindowState.Maximized) @@ -700,7 +705,7 @@ namespace Avalonia.Win32 margins.cxLeftWidth = 1; margins.cxRightWidth = 1; margins.cyBottomHeight = 1; - margins.cyTopHeight = borderThickness.top; + margins.cyTopHeight = borderCaptionThickness.top; return margins; } @@ -713,35 +718,7 @@ namespace Avalonia.Win32 return; } - RECT border_thickness = new RECT(); - MARGINS margins = new MARGINS(); - - if (GetStyle().HasFlag(WindowStyles.WS_THICKFRAME)) - { - AdjustWindowRectEx(ref border_thickness, (uint)(GetStyle()), false, 0); - border_thickness.left *= -1; - border_thickness.top *= -1; - - border_thickness.left = 1; - border_thickness.bottom = 1; - border_thickness.right = 1; - - if (!hints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar)) - { - border_thickness.top = 1; - } - - } - else if (GetStyle().HasFlag(WindowStyles.WS_BORDER)) - { - border_thickness = new RECT { bottom = 1, left = 1, right = 1, top = 1 }; - } - - // Extend the frame into the client area. - margins.cxLeftWidth = border_thickness.left; - margins.cxRightWidth = border_thickness.right; - margins.cyBottomHeight = border_thickness.bottom; - margins.cyTopHeight = border_thickness.top; + var margins = UpdateExtendMargins(hints); var hr = DwmExtendFrameIntoClientArea(_hwnd, ref margins);