From 5d327abc65ab65da15e45febbfbe4583cd7404d0 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sat, 1 Dec 2018 15:34:19 +0000 Subject: [PATCH] Revert "add CanResize checkbox to decorated window." This reverts commit 7d1f145f9331ba3b0cc47a3963b4324e20d38f3b. --- samples/ControlCatalog/DecoratedWindow.xaml | 63 ++++++++++---------- src/Windows/Avalonia.Win32/WindowImpl.cs | 64 ++++++++++----------- 2 files changed, 61 insertions(+), 66 deletions(-) diff --git a/samples/ControlCatalog/DecoratedWindow.xaml b/samples/ControlCatalog/DecoratedWindow.xaml index b2462cda26..9f05cd1f57 100644 --- a/samples/ControlCatalog/DecoratedWindow.xaml +++ b/samples/ControlCatalog/DecoratedWindow.xaml @@ -3,37 +3,36 @@ x:Class="ControlCatalog.DecoratedWindow" Title="Avalonia Control Gallery" xmlns:local="clr-namespace:ControlCatalog" HasSystemDecorations="False" Name="Window"> - - - - Title - - - - - - - - - - - - Hello world! + + + + Title + + + + + + + + + + + + Hello world! - Decorated - CanResize - - - - - - - - - - - - + Decorated + + + + + + + + + + + + diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 22dd6142fc..1383a81dd6 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -271,7 +271,9 @@ namespace Avalonia.Win32 return; } - UpdateWMStyles(() => _decorated = value); + _decorated = value; + + UpdateWMStyles(); } public void Invalidate(Rect rect) @@ -848,8 +850,7 @@ namespace Avalonia.Win32 private static int ToInt32(IntPtr ptr) { - if (IntPtr.Size == 4) - return ptr.ToInt32(); + if (IntPtr.Size == 4) return ptr.ToInt32(); return (int)(ptr.ToInt64() & 0xffffffff); } @@ -885,13 +886,8 @@ namespace Avalonia.Win32 } } - private void UpdateWMStyles(Action change) + private void UpdateWMStyles() { - var decorated = _decorated; - var resizable = _resizable; - - change(); - var style = (WindowStyles)GetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE); const WindowStyles controlledFlags = WindowStyles.WS_OVERLAPPEDWINDOW; @@ -914,35 +910,33 @@ namespace Avalonia.Win32 SetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE, (uint)style); - if (decorated != _decorated) + UnmanagedMethods.GetWindowRect(_hwnd, out var windowRect); + + Rect newRect; + + if (_decorated) { var thickness = BorderThickness; - UnmanagedMethods.GetWindowRect(_hwnd, out var windowRect); - - Rect newRect; + newRect = new Rect( + windowRect.left - thickness.Left, + windowRect.top - thickness.Top, + (windowRect.right - windowRect.left) + (thickness.Left + thickness.Right), + (windowRect.bottom - windowRect.top) + (thickness.Top + thickness.Bottom)); + } + else + { + newRect = new Rect( + windowRect.left + oldThickness.Left, + windowRect.top + oldThickness.Top, + (windowRect.right - windowRect.left) - (oldThickness.Left + oldThickness.Right), + (windowRect.bottom - windowRect.top) - (oldThickness.Top + oldThickness.Bottom)); + } - if (_decorated) - { - newRect = new Rect( - windowRect.left - thickness.Left, - windowRect.top - thickness.Top, - (windowRect.right - windowRect.left) + (thickness.Left + thickness.Right), - (windowRect.bottom - windowRect.top) + (thickness.Top + thickness.Bottom)); - } - else - { - newRect = new Rect( - windowRect.left + oldThickness.Left, - windowRect.top + oldThickness.Top, - (windowRect.right - windowRect.left) - (oldThickness.Left + oldThickness.Right), - (windowRect.bottom - windowRect.top) - (oldThickness.Top + oldThickness.Bottom)); - } + UnmanagedMethods.SetWindowPos(_hwnd, IntPtr.Zero, (int)newRect.X, (int)newRect.Y, (int)newRect.Width, + (int)newRect.Height, + UnmanagedMethods.SetWindowPosFlags.SWP_NOZORDER | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED); - UnmanagedMethods.SetWindowPos(_hwnd, IntPtr.Zero, (int)newRect.X, (int)newRect.Y, (int)newRect.Width, - (int)newRect.Height, - UnmanagedMethods.SetWindowPosFlags.SWP_NOZORDER | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED); - } } public void CanResize(bool value) @@ -952,7 +946,9 @@ namespace Avalonia.Win32 return; } - UpdateWMStyles(() => _resizable = value); + _resizable = value; + + UpdateWMStyles(); } public void SetTopmost(bool value)