Browse Source

Revert "add CanResize checkbox to decorated window."

This reverts commit 7d1f145f93.
pull/2128/head
Dan Walmsley 8 years ago
parent
commit
5d327abc65
  1. 63
      samples/ControlCatalog/DecoratedWindow.xaml
  2. 64
      src/Windows/Avalonia.Win32/WindowImpl.cs

63
samples/ControlCatalog/DecoratedWindow.xaml

@ -3,37 +3,36 @@
x:Class="ControlCatalog.DecoratedWindow" x:Class="ControlCatalog.DecoratedWindow"
Title="Avalonia Control Gallery" Title="Avalonia Control Gallery"
xmlns:local="clr-namespace:ControlCatalog" HasSystemDecorations="False" Name="Window"> xmlns:local="clr-namespace:ControlCatalog" HasSystemDecorations="False" Name="Window">
<Grid RowDefinitions="5,*,5" ColumnDefinitions="5,*,5"> <Grid RowDefinitions="5,*,5" ColumnDefinitions="5,*,5">
<DockPanel Grid.Column="1" Grid.Row="1" > <DockPanel Grid.Column="1" Grid.Row="1" >
<Grid Name="TitleBar" Background="LightBlue" DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto"> <Grid Name="TitleBar" Background="LightBlue" DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto">
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0">Title</TextBlock> <TextBlock VerticalAlignment="Center" Margin="5,0,0,0">Title</TextBlock>
<StackPanel Grid.Column="2" Orientation="Horizontal"> <StackPanel Grid.Column="2" Orientation="Horizontal">
<StackPanel.Styles> <StackPanel.Styles>
<Style Selector="Button"> <Style Selector="Button">
<Setter Property="Margin" Value="2"/> <Setter Property="Margin" Value="2"/>
</Style> </Style>
</StackPanel.Styles> </StackPanel.Styles>
<Button Name="MinimizeButton">_</Button> <Button Name="MinimizeButton">_</Button>
<Button Name="MaximizeButton">[ ]</Button> <Button Name="MaximizeButton">[ ]</Button>
<Button Name="CloseButton">X</Button> <Button Name="CloseButton">X</Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
<Border Background="White" Margin="5"> <Border Background="White" Margin="5">
<StackPanel> <StackPanel>
<TextBlock>Hello world!</TextBlock> <TextBlock>Hello world!</TextBlock>
<CheckBox IsChecked="{Binding ElementName=Window, Path=HasSystemDecorations}">Decorated</CheckBox> <CheckBox IsChecked="{Binding ElementName=Window, Path=HasSystemDecorations}">Decorated</CheckBox>
<CheckBox IsChecked="{Binding ElementName=Window, Path=CanResize}">CanResize</CheckBox> </StackPanel>
</StackPanel> </Border>
</Border> </DockPanel>
</DockPanel> <Border Name="TopLeft" Background="Red"/>
<Border Name="TopLeft" Background="Red"/> <Border Name="TopRight" Background="Red" Grid.Column="2" />
<Border Name="TopRight" Background="Red" Grid.Column="2" /> <Border Name="BottomLeft" Background="Red" Grid.Row="2" />
<Border Name="BottomLeft" Background="Red" Grid.Row="2" /> <Border Name="BottomRight" Background="Red" Grid.Row="2" Grid.Column="2"/>
<Border Name="BottomRight" Background="Red" Grid.Row="2" Grid.Column="2"/> <Border Name="Top" Background="Blue" Grid.Column="1" />
<Border Name="Top" Background="Blue" Grid.Column="1" /> <Border Name="Right" Background="Blue" Grid.Row="1" Grid.Column="2" />
<Border Name="Right" Background="Blue" Grid.Row="1" Grid.Column="2" /> <Border Name="Bottom" Background="Blue" Grid.Row="2" Grid.Column="1" />
<Border Name="Bottom" Background="Blue" Grid.Row="2" Grid.Column="1" /> <Border Name="Left" Background="Blue" Grid.Row="1" />
<Border Name="Left" Background="Blue" Grid.Row="1" /> </Grid>
</Grid>
</Window> </Window>

64
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -271,7 +271,9 @@ namespace Avalonia.Win32
return; return;
} }
UpdateWMStyles(() => _decorated = value); _decorated = value;
UpdateWMStyles();
} }
public void Invalidate(Rect rect) public void Invalidate(Rect rect)
@ -848,8 +850,7 @@ namespace Avalonia.Win32
private static int ToInt32(IntPtr ptr) private static int ToInt32(IntPtr ptr)
{ {
if (IntPtr.Size == 4) if (IntPtr.Size == 4) return ptr.ToInt32();
return ptr.ToInt32();
return (int)(ptr.ToInt64() & 0xffffffff); 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); var style = (WindowStyles)GetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE);
const WindowStyles controlledFlags = WindowStyles.WS_OVERLAPPEDWINDOW; const WindowStyles controlledFlags = WindowStyles.WS_OVERLAPPEDWINDOW;
@ -914,35 +910,33 @@ namespace Avalonia.Win32
SetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE, (uint)style); SetWindowLong(_hwnd, (int)WindowLongParam.GWL_STYLE, (uint)style);
if (decorated != _decorated) UnmanagedMethods.GetWindowRect(_hwnd, out var windowRect);
Rect newRect;
if (_decorated)
{ {
var thickness = BorderThickness; var thickness = BorderThickness;
UnmanagedMethods.GetWindowRect(_hwnd, out var windowRect); newRect = new Rect(
windowRect.left - thickness.Left,
Rect newRect; 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) UnmanagedMethods.SetWindowPos(_hwnd, IntPtr.Zero, (int)newRect.X, (int)newRect.Y, (int)newRect.Width,
{ (int)newRect.Height,
newRect = new Rect( UnmanagedMethods.SetWindowPosFlags.SWP_NOZORDER | UnmanagedMethods.SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
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);
}
} }
public void CanResize(bool value) public void CanResize(bool value)
@ -952,7 +946,9 @@ namespace Avalonia.Win32
return; return;
} }
UpdateWMStyles(() => _resizable = value); _resizable = value;
UpdateWMStyles();
} }
public void SetTopmost(bool value) public void SetTopmost(bool value)

Loading…
Cancel
Save