Browse Source

Allow extend hints to be changed at runtime.

demo1
Dan Walmsley 6 years ago
parent
commit
df41ca8f6e
  1. 11
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
  2. 60
      src/Windows/Avalonia.Win32/WindowImpl.cs

11
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

@ -373,13 +373,16 @@ namespace Avalonia.Win32
if (windowState != _lastWindowState) if (windowState != _lastWindowState)
{ {
_lastWindowState = windowState; _lastWindowState = windowState;
UpdateExtendMargins(_extendChromeHints); WindowStateChanged?.Invoke(windowState);
ExtendClientAreaToDecorationsChanged?.Invoke(true); if (_isClientAreaExtended)
{
UpdateExtendMargins();
WindowStateChanged?.Invoke(windowState); ExtendClientAreaToDecorationsChanged?.Invoke(true);
}
} }
return IntPtr.Zero; return IntPtr.Zero;

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

@ -668,7 +668,7 @@ namespace Avalonia.Win32
TaskBarList.MarkFullscreen(_hwnd, fullscreen); TaskBarList.MarkFullscreen(_hwnd, fullscreen);
} }
private MARGINS UpdateExtendMargins(ExtendClientAreaChromeHints hints) private MARGINS UpdateExtendMargins()
{ {
RECT borderThickness = new RECT(); RECT borderThickness = new RECT();
RECT borderCaptionThickness = new RECT(); RECT borderCaptionThickness = new RECT();
@ -680,7 +680,7 @@ namespace Avalonia.Win32
borderCaptionThickness.left *= -1; borderCaptionThickness.left *= -1;
borderCaptionThickness.top *= -1; borderCaptionThickness.top *= -1;
bool wantsTitleBar = hints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar) || _extendTitleBarHint == -1; bool wantsTitleBar = _extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar) || _extendTitleBarHint == -1;
if (!wantsTitleBar) if (!wantsTitleBar)
{ {
@ -697,7 +697,7 @@ namespace Avalonia.Win32
borderCaptionThickness.top = (int)(_extendTitleBarHint * Scaling); borderCaptionThickness.top = (int)(_extendTitleBarHint * Scaling);
} }
margins.cyTopHeight = hints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar) ? borderCaptionThickness.top : 1; margins.cyTopHeight = _extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar) ? borderCaptionThickness.top : 1;
_extendedMargins = new Thickness(0, borderCaptionThickness.top / Scaling, 0, 0); _extendedMargins = new Thickness(0, borderCaptionThickness.top / Scaling, 0, 0);
@ -713,22 +713,32 @@ namespace Avalonia.Win32
return margins; return margins;
} }
private void ExtendClientArea (ExtendClientAreaChromeHints hints) private void ExtendClientArea ()
{ {
if (!_isClientAreaExtended) if (DwmIsCompositionEnabled(out bool compositionEnabled) < 0 || !compositionEnabled)
{ {
if(DwmIsCompositionEnabled(out bool compositionEnabled) < 0 || !compositionEnabled) _isClientAreaExtended = false;
{ return;
return; }
}
var margins = UpdateExtendMargins(hints); GetWindowRect(_hwnd, out var rcClient);
var hr = DwmExtendFrameIntoClientArea(_hwnd, ref margins); // Inform the application of the frame change.
SetWindowPos(_hwnd,
IntPtr.Zero,
rcClient.left, rcClient.top,
rcClient.Width, rcClient.Height,
SetWindowPosFlags.SWP_FRAMECHANGED);
if(_isClientAreaExtended)
{
var margins = UpdateExtendMargins();
if(!hints.HasFlag(ExtendClientAreaChromeHints.SystemChromeButtons) || DwmExtendFrameIntoClientArea(_hwnd, ref margins);
(hints.HasFlag(ExtendClientAreaChromeHints.PreferSystemChromeButtons) &&
!hints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar))) if(!_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemChromeButtons) ||
(_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.PreferSystemChromeButtons) &&
!_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar)))
{ {
var style = GetStyle(); var style = GetStyle();
@ -738,13 +748,17 @@ namespace Avalonia.Win32
DisableCloseButton(_hwnd); DisableCloseButton(_hwnd);
} }
}
else
{
var margins = new MARGINS();
DwmExtendFrameIntoClientArea(_hwnd, ref margins);
if (hr == 0) _offScreenMargin = new Thickness();
{ _extendedMargins = new Thickness();
_isClientAreaExtended = true;
ExtendClientAreaToDecorationsChanged?.Invoke(true);
}
} }
ExtendClientAreaToDecorationsChanged?.Invoke(true);
} }
private void ShowWindow(WindowState state) private void ShowWindow(WindowState state)
@ -1011,7 +1025,9 @@ namespace Avalonia.Win32
public void SetExtendClientAreaToDecorationsHint(bool hint) public void SetExtendClientAreaToDecorationsHint(bool hint)
{ {
ExtendClientArea(_extendChromeHints); _isClientAreaExtended = hint;
ExtendClientArea();
} }
private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default;
@ -1019,12 +1035,16 @@ namespace Avalonia.Win32
public void SetExtendClientAreaChromeHints(ExtendClientAreaChromeHints hints) public void SetExtendClientAreaChromeHints(ExtendClientAreaChromeHints hints)
{ {
_extendChromeHints = hints; _extendChromeHints = hints;
ExtendClientArea();
} }
private double _extendTitleBarHint = -1; private double _extendTitleBarHint = -1;
public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight) public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight)
{ {
_extendTitleBarHint = titleBarHeight; _extendTitleBarHint = titleBarHeight;
ExtendClientArea();
} }
public bool IsClientAreaExtendedToDecorations => _isClientAreaExtended; public bool IsClientAreaExtendedToDecorations => _isClientAreaExtended;

Loading…
Cancel
Save