Browse Source

Revert "add CanResize checkbox to decorated window."

This reverts commit 7d1f145f9331ba3b0cc47a3963b4324e20d38f3b.
Dan Walmsley 7 years ago
parent
commit
5d327abc65
2 changed files with 61 additions and 66 deletions
  1. 31 32
      samples/ControlCatalog/DecoratedWindow.xaml
  2. 30 34
      src/Windows/Avalonia.Win32/WindowImpl.cs

+ 31 - 32
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">
-    <Grid RowDefinitions="5,*,5" ColumnDefinitions="5,*,5">
-        <DockPanel  Grid.Column="1"  Grid.Row="1" >
-            <Grid Name="TitleBar" Background="LightBlue" DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto">
-                <TextBlock VerticalAlignment="Center" Margin="5,0,0,0">Title</TextBlock>
-                <StackPanel Grid.Column="2" Orientation="Horizontal">
-                    <StackPanel.Styles>
-                        <Style Selector="Button">
-                            <Setter Property="Margin" Value="2"/>
-                        </Style>
-                    </StackPanel.Styles>
-                    <Button Name="MinimizeButton">_</Button>
-                    <Button Name="MaximizeButton">[ ]</Button>
-                    <Button Name="CloseButton">X</Button>
-                </StackPanel>
-            </Grid>
-            <Border Background="White" Margin="5">
-                <StackPanel>
-                    <TextBlock>Hello world!</TextBlock>
+  <Grid RowDefinitions="5,*,5" ColumnDefinitions="5,*,5">
+    <DockPanel  Grid.Column="1"  Grid.Row="1" >
+      <Grid Name="TitleBar" Background="LightBlue" DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto">
+      <TextBlock VerticalAlignment="Center" Margin="5,0,0,0">Title</TextBlock>
+        <StackPanel Grid.Column="2" Orientation="Horizontal">
+          <StackPanel.Styles>
+            <Style Selector="Button">
+              <Setter Property="Margin" Value="2"/>
+            </Style>
+          </StackPanel.Styles>
+        <Button Name="MinimizeButton">_</Button>
+        <Button Name="MaximizeButton">[ ]</Button>
+        <Button Name="CloseButton">X</Button>
+        </StackPanel>
+      </Grid>
+      <Border Background="White" Margin="5">
+        <StackPanel>
+        <TextBlock>Hello world!</TextBlock>
 
-                    <CheckBox IsChecked="{Binding ElementName=Window, Path=HasSystemDecorations}">Decorated</CheckBox>
-                    <CheckBox IsChecked="{Binding ElementName=Window, Path=CanResize}">CanResize</CheckBox>
-                </StackPanel>
-            </Border>
-        </DockPanel>
-        <Border Name="TopLeft" Background="Red"/>
-        <Border Name="TopRight" Background="Red" Grid.Column="2" />
-        <Border Name="BottomLeft" Background="Red" Grid.Row="2" />
-        <Border Name="BottomRight" Background="Red"  Grid.Row="2" Grid.Column="2"/>
-        <Border Name="Top" Background="Blue" Grid.Column="1" />
-        <Border Name="Right" Background="Blue" Grid.Row="1"  Grid.Column="2" />
-        <Border Name="Bottom" Background="Blue" Grid.Row="2" Grid.Column="1"  />
-        <Border Name="Left" Background="Blue"  Grid.Row="1" />
-    </Grid>
+        <CheckBox IsChecked="{Binding ElementName=Window, Path=HasSystemDecorations}">Decorated</CheckBox>
+        </StackPanel>
+      </Border>
+    </DockPanel>
+    <Border Name="TopLeft" Background="Red"/>
+    <Border Name="TopRight" Background="Red" Grid.Column="2" />
+    <Border Name="BottomLeft" Background="Red" Grid.Row="2" />
+    <Border Name="BottomRight" Background="Red"  Grid.Row="2" Grid.Column="2"/>
+    <Border Name="Top" Background="Blue" Grid.Column="1" />
+    <Border Name="Right" Background="Blue" Grid.Row="1"  Grid.Column="2" />
+    <Border Name="Bottom" Background="Blue" Grid.Row="2" Grid.Column="1"  />
+    <Border Name="Left" Background="Blue"  Grid.Row="1" />
+  </Grid>
 </Window>

+ 30 - 34
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)