Browse Source

Merge pull request #8112 from AvaloniaUI/osx-nswindow-refactor-part4

[OSX] cache IsClientAreaExtendedToDecorations, and apply it when NSPa…
pull/8157/head
Dan Walmsley 4 years ago
parent
commit
0054183e8a
  1. 56
      native/Avalonia.Native/src/OSX/WindowImpl.mm
  2. 2
      samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
  3. 7
      src/Avalonia.Native/WindowImpl.cs

56
native/Avalonia.Native/src/OSX/WindowImpl.mm

@ -54,8 +54,20 @@ HRESULT WindowImpl::Show(bool activate, bool isDialog) {
@autoreleasepool {
_isDialog = isDialog;
bool created = Window == nullptr;
WindowBaseImpl::Show(activate, isDialog);
if(created)
{
if(_isClientAreaExtended)
{
[GetWindowProtocol() setIsExtended:true];
SetExtendClientArea(true);
}
}
HideOrShowTrafficLights();
return SetWindowState(_lastWindowState);
@ -326,37 +338,39 @@ HRESULT WindowImpl::SetExtendClientArea(bool enable) {
@autoreleasepool {
_isClientAreaExtended = enable;
if (enable) {
Window.titleVisibility = NSWindowTitleHidden;
if(Window != nullptr) {
if (enable) {
Window.titleVisibility = NSWindowTitleHidden;
[Window setTitlebarAppearsTransparent:true];
[Window setTitlebarAppearsTransparent:true];
auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
auto wantsTitleBar = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
if (wantsTitleBar) {
[StandardContainer ShowTitleBar:true];
} else {
[StandardContainer ShowTitleBar:false];
}
if (wantsTitleBar) {
[StandardContainer ShowTitleBar:true];
} else {
[StandardContainer ShowTitleBar:false];
}
if (_extendClientHints & AvnOSXThickTitleBar) {
Window.toolbar = [NSToolbar new];
Window.toolbar.showsBaselineSeparator = false;
if (_extendClientHints & AvnOSXThickTitleBar) {
Window.toolbar = [NSToolbar new];
Window.toolbar.showsBaselineSeparator = false;
} else {
Window.toolbar = nullptr;
}
} else {
Window.titleVisibility = NSWindowTitleVisible;
Window.toolbar = nullptr;
[Window setTitlebarAppearsTransparent:false];
View.layer.zPosition = 0;
}
} else {
Window.titleVisibility = NSWindowTitleVisible;
Window.toolbar = nullptr;
[Window setTitlebarAppearsTransparent:false];
View.layer.zPosition = 0;
}
[GetWindowProtocol() setIsExtended:enable];
[GetWindowProtocol() setIsExtended:enable];
HideOrShowTrafficLights();
HideOrShowTrafficLights();
UpdateStyle();
UpdateStyle();
}
return S_OK;
}

2
samples/ControlCatalog/ViewModels/MainWindowViewModel.cs

@ -17,7 +17,7 @@ namespace ControlCatalog.ViewModels
private WindowState _windowState;
private WindowState[] _windowStates;
private int _transparencyLevel;
private ExtendClientAreaChromeHints _chromeHints;
private ExtendClientAreaChromeHints _chromeHints = ExtendClientAreaChromeHints.PreferSystemChrome;
private bool _extendClientAreaEnabled;
private bool _systemTitleBarEnabled;
private bool _preferSystemChromeEnabled;

7
src/Avalonia.Native/WindowImpl.cs

@ -108,6 +108,13 @@ namespace Avalonia.Native
private bool _isExtended;
public bool IsClientAreaExtendedToDecorations => _isExtended;
public override void Show(bool activate, bool isDialog)
{
base.Show(activate, isDialog);
InvalidateExtendedMargins();
}
protected override bool ChromeHitTest (RawPointerEventArgs e)
{
if(_isExtended)

Loading…
Cancel
Save