diff --git a/build/ApiCompatAttributeExcludeList.txt b/build/ApiCompatAttributeExcludeList.txt
new file mode 100644
index 0000000000..1df5a30ec3
--- /dev/null
+++ b/build/ApiCompatAttributeExcludeList.txt
@@ -0,0 +1,2 @@
+T:Avalonia.Metadata.NotClientImplementableAttribute
+T:Avalonia.Metadata.UnstableAttribute
diff --git a/build/CoreLibraries.props b/build/CoreLibraries.props
index 314d38190a..9448a31d73 100644
--- a/build/CoreLibraries.props
+++ b/build/CoreLibraries.props
@@ -3,8 +3,6 @@
-
-
diff --git a/native/Avalonia.Native/inc/rendertarget.h b/native/Avalonia.Native/inc/rendertarget.h
index 2b0338d099..a59915777f 100644
--- a/native/Avalonia.Native/inc/rendertarget.h
+++ b/native/Avalonia.Native/inc/rendertarget.h
@@ -1,3 +1,8 @@
+#pragma once
+
+#include "com.h"
+#include "comimpl.h"
+#include "avalonia-native.h"
@protocol IRenderTarget
-(void) setNewLayer: (CALayer*) layer;
diff --git a/native/Avalonia.Native/src/OSX/AutoFitContentView.h b/native/Avalonia.Native/src/OSX/AutoFitContentView.h
index 68c9fb8dc8..7f1f764141 100644
--- a/native/Avalonia.Native/src/OSX/AutoFitContentView.h
+++ b/native/Avalonia.Native/src/OSX/AutoFitContentView.h
@@ -3,8 +3,10 @@
// Copyright (c) 2022 Avalonia. All rights reserved.
//
+#pragma once
+
#import
-#import "avalonia-native.h"
+#include "avalonia-native.h"
@interface AutoFitContentView : NSView
-(AutoFitContentView* _Nonnull) initWithContent: (NSView* _Nonnull) content;
diff --git a/native/Avalonia.Native/src/OSX/AutoFitContentView.mm b/native/Avalonia.Native/src/OSX/AutoFitContentView.mm
index 92d6f67a91..0fa4540726 100644
--- a/native/Avalonia.Native/src/OSX/AutoFitContentView.mm
+++ b/native/Avalonia.Native/src/OSX/AutoFitContentView.mm
@@ -4,7 +4,9 @@
//
#include "AvnView.h"
-#import "AutoFitContentView.h"
+#include "AutoFitContentView.h"
+#include "WindowInterfaces.h"
+#include "WindowProtocol.h"
@implementation AutoFitContentView
{
@@ -83,7 +85,7 @@
_settingSize = true;
[super setFrameSize:newSize];
- auto window = objc_cast([self window]);
+ auto window = (id ) [self window];
// TODO get actual titlebar size
diff --git a/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj b/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj
index 88e4c0c682..6fc3977d4e 100644
--- a/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj
+++ b/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/project.pbxproj
@@ -9,16 +9,22 @@
/* Begin PBXBuildFile section */
18391068E48EF96E3DB5FDAB /* ResizeScope.mm in Sources */ = {isa = PBXBuildFile; fileRef = 18391E45702740FE9DD69695 /* ResizeScope.mm */; };
1839125F057B0A4EB1760058 /* WindowImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 183919BF108EB72A029F7671 /* WindowImpl.mm */; };
+ 183914E50CF6D2EFC1667F7C /* WindowInterfaces.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391DB45C7D892E61BF388C /* WindowInterfaces.h */; };
+ 1839151F32D1BB1AB51A7BB6 /* AvnPanelWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 18391884C7476DA4E53A492D /* AvnPanelWindow.mm */; };
183916173528EC2737DBE5E1 /* WindowBaseImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 183915BFF0E234CD3604A7CD /* WindowBaseImpl.h */; };
1839171DCC651B0638603AC4 /* INSWindowHolder.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391BBB7782C296D424071F /* INSWindowHolder.h */; };
1839179A55FC1421BEE83330 /* WindowBaseImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 18391676ECF0E983F4964357 /* WindowBaseImpl.mm */; };
183919D91DB9AAB5D700C2EA /* WindowImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391CD090AA776E7E841AC9 /* WindowImpl.h */; };
18391AA7E0BBA74D184C5734 /* AutoFitContentView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1839166350F32661F3ABD70F /* AutoFitContentView.mm */; };
+ 18391AC16726CBC45856233B /* AvnWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1839155B28B20FFB672D29C6 /* AvnWindow.mm */; };
+ 18391AC65ADD7DDD33FBE737 /* PopupImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 183910513F396141938832B5 /* PopupImpl.h */; };
18391C28BF1823B5464FDD36 /* ResizeScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 1839171D898F9BFC1373631A /* ResizeScope.h */; };
18391CF07316F819E76B617C /* IWindowStateChanged.h in Headers */ = {isa = PBXBuildFile; fileRef = 183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */; };
18391D4EB311BC7EF8B8C0A6 /* AvnView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1839132D0E2454D911F1D1F9 /* AvnView.mm */; };
+ 18391D8CD1756DC858DC1A09 /* PopupImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 18391BB698579F40F1783F31 /* PopupImpl.mm */; };
18391E1381E2D5BFD60265A9 /* AutoFitContentView.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391654EF0E7AB3D3AB4071 /* AutoFitContentView.h */; };
18391ED5F611FF62C45F196D /* AvnView.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391D1669284AD2EC9E866A /* AvnView.h */; };
+ 18391F1E2411C79405A9943A /* WindowProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 1839122E037567BDD1D09DEB /* WindowProtocol.h */; };
1A002B9E232135EE00021753 /* app.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A002B9D232135EE00021753 /* app.mm */; };
1A1852DC23E05814008F0DED /* deadlock.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A1852DB23E05814008F0DED /* deadlock.mm */; };
1A3E5EA823E9E83B00EDE661 /* rendertarget.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A3E5EA723E9E83B00EDE661 /* rendertarget.mm */; };
@@ -40,24 +46,29 @@
AB00E4F72147CA920032A60A /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB00E4F62147CA920032A60A /* main.mm */; };
AB1E522C217613570091CD71 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB1E522B217613570091CD71 /* OpenGL.framework */; };
AB661C1E2148230F00291242 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB661C1D2148230F00291242 /* AppKit.framework */; };
- AB661C202148286E00291242 /* window.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB661C1F2148286E00291242 /* window.mm */; };
AB8F7D6B21482D7F0057DBA5 /* platformthreading.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB8F7D6A21482D7F0057DBA5 /* platformthreading.mm */; };
BC11A5BE2608D58F0017BAD0 /* automation.h in Headers */ = {isa = PBXBuildFile; fileRef = BC11A5BC2608D58F0017BAD0 /* automation.h */; };
BC11A5BF2608D58F0017BAD0 /* automation.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC11A5BD2608D58F0017BAD0 /* automation.mm */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 183910513F396141938832B5 /* PopupImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PopupImpl.h; sourceTree = ""; };
+ 1839122E037567BDD1D09DEB /* WindowProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowProtocol.h; sourceTree = ""; };
1839132D0E2454D911F1D1F9 /* AvnView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AvnView.mm; sourceTree = ""; };
183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IWindowStateChanged.h; sourceTree = ""; };
+ 1839155B28B20FFB672D29C6 /* AvnWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AvnWindow.mm; sourceTree = ""; };
183915BFF0E234CD3604A7CD /* WindowBaseImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowBaseImpl.h; sourceTree = ""; };
18391654EF0E7AB3D3AB4071 /* AutoFitContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoFitContentView.h; sourceTree = ""; };
1839166350F32661F3ABD70F /* AutoFitContentView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoFitContentView.mm; sourceTree = ""; };
18391676ECF0E983F4964357 /* WindowBaseImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowBaseImpl.mm; sourceTree = ""; };
1839171D898F9BFC1373631A /* ResizeScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResizeScope.h; sourceTree = ""; };
+ 18391884C7476DA4E53A492D /* AvnPanelWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AvnPanelWindow.mm; sourceTree = ""; };
183919BF108EB72A029F7671 /* WindowImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowImpl.mm; sourceTree = ""; };
+ 18391BB698579F40F1783F31 /* PopupImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PopupImpl.mm; sourceTree = ""; };
18391BBB7782C296D424071F /* INSWindowHolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INSWindowHolder.h; sourceTree = ""; };
18391CD090AA776E7E841AC9 /* WindowImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowImpl.h; sourceTree = ""; };
18391D1669284AD2EC9E866A /* AvnView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AvnView.h; sourceTree = ""; };
+ 18391DB45C7D892E61BF388C /* WindowInterfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowInterfaces.h; sourceTree = ""; };
18391E45702740FE9DD69695 /* ResizeScope.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResizeScope.mm; sourceTree = ""; };
1A002B9D232135EE00021753 /* app.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = app.mm; sourceTree = ""; };
1A1852DB23E05814008F0DED /* deadlock.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = deadlock.mm; sourceTree = ""; };
@@ -72,7 +83,6 @@
37A4E71A2178846A00EACBCD /* headers */ = {isa = PBXFileReference; lastKnownFileType = folder; name = headers; path = ../../inc; sourceTree = ""; };
37A517B22159597E00FBA241 /* Screens.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Screens.mm; sourceTree = ""; };
37C09D8721580FE4006A6758 /* SystemDialogs.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemDialogs.mm; sourceTree = ""; };
- 37C09D8A21581EF2006A6758 /* window.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = window.h; sourceTree = ""; };
37DDA9AF219330F8002E132B /* AvnString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AvnString.mm; sourceTree = ""; };
37DDA9B121933371002E132B /* AvnString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AvnString.h; sourceTree = ""; };
37E2330E21583241000CB7E2 /* KeyTransform.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyTransform.mm; sourceTree = ""; };
@@ -86,7 +96,6 @@
AB00E4F62147CA920032A60A /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = ""; };
AB1E522B217613570091CD71 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
AB661C1D2148230F00291242 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
- AB661C1F2148286E00291242 /* window.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = window.mm; sourceTree = ""; };
AB661C212148288600291242 /* common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = ""; };
AB7A61EF2147C815003C5833 /* libAvalonia.Native.OSX.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libAvalonia.Native.OSX.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
AB8F7D6A21482D7F0057DBA5 /* platformthreading.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = platformthreading.mm; sourceTree = ""; };
@@ -142,8 +151,6 @@
AB661C212148288600291242 /* common.h */,
379860FE214DA0C000CD0246 /* KeyTransform.h */,
37E2330E21583241000CB7E2 /* KeyTransform.mm */,
- AB661C1F2148286E00291242 /* window.mm */,
- 37C09D8A21581EF2006A6758 /* window.h */,
AB00E4F62147CA920032A60A /* main.mm */,
37155CE3233C00EB0034DCE9 /* menu.h */,
520624B222973F4100C4DCEF /* menu.mm */,
@@ -166,6 +173,12 @@
18391D1669284AD2EC9E866A /* AvnView.h */,
1839166350F32661F3ABD70F /* AutoFitContentView.mm */,
18391654EF0E7AB3D3AB4071 /* AutoFitContentView.h */,
+ 18391884C7476DA4E53A492D /* AvnPanelWindow.mm */,
+ 1839122E037567BDD1D09DEB /* WindowProtocol.h */,
+ 1839155B28B20FFB672D29C6 /* AvnWindow.mm */,
+ 18391DB45C7D892E61BF388C /* WindowInterfaces.h */,
+ 18391BB698579F40F1783F31 /* PopupImpl.mm */,
+ 183910513F396141938832B5 /* PopupImpl.h */,
);
sourceTree = "";
};
@@ -193,6 +206,9 @@
18391C28BF1823B5464FDD36 /* ResizeScope.h in Headers */,
18391ED5F611FF62C45F196D /* AvnView.h in Headers */,
18391E1381E2D5BFD60265A9 /* AutoFitContentView.h in Headers */,
+ 18391F1E2411C79405A9943A /* WindowProtocol.h in Headers */,
+ 183914E50CF6D2EFC1667F7C /* WindowInterfaces.h in Headers */,
+ 18391AC65ADD7DDD33FBE737 /* PopupImpl.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -271,12 +287,14 @@
1A465D10246AB61600C5858B /* dnd.mm in Sources */,
AB00E4F72147CA920032A60A /* main.mm in Sources */,
37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */,
- AB661C202148286E00291242 /* window.mm in Sources */,
1839179A55FC1421BEE83330 /* WindowBaseImpl.mm in Sources */,
1839125F057B0A4EB1760058 /* WindowImpl.mm in Sources */,
18391068E48EF96E3DB5FDAB /* ResizeScope.mm in Sources */,
18391D4EB311BC7EF8B8C0A6 /* AvnView.mm in Sources */,
18391AA7E0BBA74D184C5734 /* AutoFitContentView.mm in Sources */,
+ 1839151F32D1BB1AB51A7BB6 /* AvnPanelWindow.mm in Sources */,
+ 18391AC16726CBC45856233B /* AvnWindow.mm in Sources */,
+ 18391D8CD1756DC858DC1A09 /* PopupImpl.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/native/Avalonia.Native/src/OSX/AvnPanelWindow.mm b/native/Avalonia.Native/src/OSX/AvnPanelWindow.mm
new file mode 100644
index 0000000000..2365189010
--- /dev/null
+++ b/native/Avalonia.Native/src/OSX/AvnPanelWindow.mm
@@ -0,0 +1,11 @@
+//
+// Created by Dan Walmsley on 06/05/2022.
+// Copyright (c) 2022 Avalonia. All rights reserved.
+//
+
+#pragma once
+
+#define IS_NSPANEL
+
+#include "AvnWindow.mm"
+
diff --git a/native/Avalonia.Native/src/OSX/AvnView.h b/native/Avalonia.Native/src/OSX/AvnView.h
index c6dd90150f..86a68d34c5 100644
--- a/native/Avalonia.Native/src/OSX/AvnView.h
+++ b/native/Avalonia.Native/src/OSX/AvnView.h
@@ -2,17 +2,15 @@
// Created by Dan Walmsley on 05/05/2022.
// Copyright (c) 2022 Avalonia. All rights reserved.
//
-
+#pragma once
#import
#import
#import
-#include "window.h"
-#import "comimpl.h"
-#import "common.h"
-#import "WindowImpl.h"
-#import "KeyTransform.h"
+#include "common.h"
+#include "WindowImpl.h"
+#include "KeyTransform.h"
@class AvnAccessibilityElement;
diff --git a/native/Avalonia.Native/src/OSX/AvnView.mm b/native/Avalonia.Native/src/OSX/AvnView.mm
index 24cbc25502..02526afbcb 100644
--- a/native/Avalonia.Native/src/OSX/AvnView.mm
+++ b/native/Avalonia.Native/src/OSX/AvnView.mm
@@ -4,8 +4,9 @@
//
#import
-#import "AvnView.h"
+#include "AvnView.h"
#include "automation.h"
+#import "WindowInterfaces.h"
@implementation AvnView
{
@@ -194,7 +195,12 @@
- (bool) ignoreUserInput:(bool)trigerInputWhenDisabled
{
- auto parentWindow = objc_cast([self window]);
+ if(_parent == nullptr)
+ {
+ return TRUE;
+ }
+
+ auto parentWindow = _parent->GetWindowProtocol();
if(parentWindow == nil || ![parentWindow shouldTryToHandleEvents])
{
diff --git a/native/Avalonia.Native/src/OSX/window.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm
similarity index 78%
rename from native/Avalonia.Native/src/OSX/window.mm
rename to native/Avalonia.Native/src/OSX/AvnWindow.mm
index 68a459d088..f51c693777 100644
--- a/native/Avalonia.Native/src/OSX/window.mm
+++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm
@@ -1,18 +1,37 @@
+//
+// Created by Dan Walmsley on 06/05/2022.
+// Copyright (c) 2022 Avalonia. All rights reserved.
+//
+
+
+#import
+#import "WindowProtocol.h"
+#import "WindowBaseImpl.h"
+
+#ifdef IS_NSPANEL
+#define BASE_CLASS NSPanel
+#define CLASS_NAME AvnPanel
+#else
+#define BASE_CLASS NSWindow
+#define CLASS_NAME AvnWindow
+#endif
+
#import
#include "common.h"
-#import "window.h"
#include "menu.h"
#include "automation.h"
-#import "WindowBaseImpl.h"
+#include "WindowBaseImpl.h"
#include "WindowImpl.h"
#include "AvnView.h"
+#include "WindowInterfaces.h"
+#include "PopupImpl.h"
-@implementation AvnWindow
+@implementation CLASS_NAME
{
ComPtr _parent;
- bool _canBecomeKeyAndMain;
bool _closed;
bool _isEnabled;
+ bool _canBecomeKeyWindow;
bool _isExtended;
AvnMenu* _menu;
}
@@ -66,7 +85,7 @@
- (void)pollModalSession:(nonnull NSModalSession)session
{
auto response = [NSApp runModalSession:session];
-
+
if(response == NSModalResponseContinue)
{
dispatch_async(dispatch_get_main_queue(), ^{
@@ -85,18 +104,18 @@
if(_menu != nullptr)
{
auto appMenuItem = ::GetAppMenuItem();
-
+
if(appMenuItem != nullptr)
{
auto appMenu = [appMenuItem menu];
-
+
[appMenu removeItem:appMenuItem];
-
+
[_menu insertItem:appMenuItem atIndex:0];
-
+
[_menu setHasGlobalMenuItem:true];
}
-
+
[NSApp setMenu:_menu];
}
else
@@ -108,22 +127,22 @@
-(void) showAppMenuOnly
{
auto appMenuItem = ::GetAppMenuItem();
-
+
if(appMenuItem != nullptr)
{
auto appMenu = ::GetAppMenu();
-
+
auto nativeAppMenu = dynamic_cast(appMenu);
-
+
[[appMenuItem menu] removeItem:appMenuItem];
-
+
if(_menu != nullptr)
{
[_menu setHasGlobalMenuItem:false];
}
-
+
[nativeAppMenu->GetNative() addItem:appMenuItem];
-
+
[NSApp setMenu:nativeAppMenu->GetNative()];
}
}
@@ -134,40 +153,45 @@
{
menu = [AvnMenu new];
}
-
+
_menu = menu;
}
--(void) setCanBecomeKeyAndMain
+-(CLASS_NAME*) initWithParent: (WindowBaseImpl*) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask;
{
- _canBecomeKeyAndMain = true;
-}
+ // https://jameshfisher.com/2020/07/10/why-is-the-contentrect-of-my-nswindow-ignored/
+ // create nswindow with specific contentRect, otherwise we wont be able to resize the window
+ // until several ms after the window is physically on the screen.
+ self = [super initWithContentRect:contentRect styleMask: styleMask backing:NSBackingStoreBuffered defer:false];
--(AvnWindow*) initWithParent: (WindowBaseImpl*) parent
-{
- self = [super init];
[self setReleasedWhenClosed:false];
_parent = parent;
[self setDelegate:self];
_closed = false;
_isEnabled = true;
-
+
[self backingScaleFactor];
[self setOpaque:NO];
[self setBackgroundColor: [NSColor clearColor]];
+
_isExtended = false;
+
+#ifdef IS_NSPANEL
+ [self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
+#endif
+
return self;
}
- (BOOL)windowShouldClose:(NSWindow *)sender
{
auto window = dynamic_cast(_parent.getRaw());
-
+
if(window != nullptr)
{
return !window->WindowEvents->Closing();
}
-
+
return true;
}
@@ -176,6 +200,8 @@
[self backingScaleFactor];
}
+
+
- (void)windowWillClose:(NSNotification *)notification
{
_closed = true;
@@ -191,27 +217,38 @@
-(BOOL)canBecomeKeyWindow
{
- if (_canBecomeKeyAndMain)
+ if(_canBecomeKeyWindow)
{
// If the window has a child window being shown as a dialog then don't allow it to become the key window.
for(NSWindow* uch in [self childWindows])
{
- auto ch = objc_cast(uch);
- if(ch == nil)
+ if (![uch conformsToProtocol:@protocol(AvnWindowProtocol)])
+ {
continue;
- if (ch.isDialog)
+ }
+
+ id ch = (id ) uch;
+
+ if(ch.isDialog)
return false;
}
-
+
return true;
}
return false;
}
+#ifndef IS_NSPANEL
-(BOOL)canBecomeMainWindow
{
- return _canBecomeKeyAndMain;
+ return true;
+}
+#endif
+
+-(void)setCanBecomeKeyWindow:(bool)value
+{
+ _canBecomeKeyWindow = value;
}
-(bool)shouldTryToHandleEvents
@@ -227,7 +264,7 @@
-(void)becomeKeyWindow
{
[self showWindowMenuWithAppMenu];
-
+
if(_parent != nullptr)
{
_parent->BaseEvents->Activated();
@@ -238,7 +275,8 @@
-(void) restoreParentWindow;
{
- auto parent = objc_cast([self parentWindow]);
+ auto parent = [self parentWindow];
+
if(parent != nil)
{
[parent removeChildWindow:self];
@@ -248,7 +286,7 @@
- (void)windowDidMiniaturize:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->WindowStateChanged();
@@ -258,7 +296,7 @@
- (void)windowDidDeminiaturize:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->WindowStateChanged();
@@ -268,7 +306,7 @@
- (void)windowDidResize:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->WindowStateChanged();
@@ -278,7 +316,7 @@
- (void)windowWillExitFullScreen:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->StartStateTransition();
@@ -288,22 +326,22 @@
- (void)windowDidExitFullScreen:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->EndStateTransition();
-
+
if(parent->Decorations() != SystemDecorationsFull && parent->WindowState() == Maximized)
{
NSRect screenRect = [[self screen] visibleFrame];
[self setFrame:screenRect display:YES];
}
-
+
if(parent->WindowState() == Minimized)
{
[self miniaturize:nullptr];
}
-
+
parent->WindowStateChanged();
}
}
@@ -311,7 +349,7 @@
- (void)windowWillEnterFullScreen:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->StartStateTransition();
@@ -321,7 +359,7 @@
- (void)windowDidEnterFullScreen:(NSNotification *)notification
{
auto parent = dynamic_cast(_parent.operator->());
-
+
if(parent != nullptr)
{
parent->EndStateTransition();
@@ -338,28 +376,33 @@
{
if(_parent)
_parent->BaseEvents->Deactivated();
-
+
[self showAppMenuOnly];
-
+
[super resignKeyWindow];
}
- (void)windowDidMove:(NSNotification *)notification
{
AvnPoint position;
-
+
if(_parent != nullptr)
{
auto cparent = dynamic_cast(_parent.getRaw());
-
+
if(cparent != nullptr)
{
+ if(!cparent->IsShown())
+ {
+ return;
+ }
+
if(cparent->WindowState() == Maximized)
{
cparent->SetWindowState(Normal);
}
}
-
+
_parent->GetPosition(&position);
_parent->BaseEvents->PositionChanged(position);
}
@@ -374,7 +417,7 @@
- (void)sendEvent:(NSEvent *)event
{
[super sendEvent:event];
-
+
/// This is to detect non-client clicks. This can only be done on Windows... not popups, hence the dynamic_cast.
if(_parent != nullptr && dynamic_cast(_parent.getRaw()) != nullptr)
{
@@ -385,95 +428,39 @@
AvnView* view = _parent->View;
NSPoint windowPoint = [event locationInWindow];
NSPoint viewPoint = [view convertPoint:windowPoint fromView:nil];
-
+
if (!NSPointInRect(viewPoint, view.bounds))
{
auto avnPoint = [AvnView toAvnPoint:windowPoint];
auto point = [self translateLocalPoint:avnPoint];
AvnVector delta = { 0, 0 };
-
+
_parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast([event timestamp] * 1000), AvnInputModifiersNone, point, delta);
}
}
- break;
-
+ break;
+
case NSEventTypeMouseEntered:
{
_parent->UpdateCursor();
}
- break;
-
+ break;
+
case NSEventTypeMouseExited:
{
[[NSCursor arrowCursor] set];
}
- break;
-
+ break;
+
default:
break;
}
}
}
-@end
-
-class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup
-{
-private:
- BEGIN_INTERFACE_MAP()
- INHERIT_INTERFACE_MAP(WindowBaseImpl)
- INTERFACE_MAP_ENTRY(IAvnPopup, IID_IAvnPopup)
- END_INTERFACE_MAP()
- virtual ~PopupImpl(){}
- ComPtr WindowEvents;
- PopupImpl(IAvnWindowEvents* events, IAvnGlContext* gl) : WindowBaseImpl(events, gl)
- {
- WindowEvents = events;
- [Window setLevel:NSPopUpMenuWindowLevel];
- }
-protected:
- virtual NSWindowStyleMask GetStyle() override
- {
- return NSWindowStyleMaskBorderless;
- }
-
- virtual HRESULT Resize(double x, double y, AvnPlatformResizeReason reason) override
- {
- START_COM_CALL;
-
- @autoreleasepool
- {
- if (Window != nullptr)
- {
- [Window setContentSize:NSSize{x, y}];
-
- [Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(lastPositionSet))];
- }
-
- return S_OK;
- }
- }
-public:
- virtual bool ShouldTakeFocusOnShow() override
- {
- return false;
- }
-};
-
-extern IAvnPopup* CreateAvnPopup(IAvnWindowEvents*events, IAvnGlContext* gl)
-{
- @autoreleasepool
- {
- IAvnPopup* ptr = dynamic_cast(new PopupImpl(events, gl));
- return ptr;
- }
+- (void)disconnectParent {
+ _parent = nullptr;
}
-extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events, IAvnGlContext* gl)
-{
- @autoreleasepool
- {
- IAvnWindow* ptr = (IAvnWindow*)new WindowImpl(events, gl);
- return ptr;
- }
-}
+@end
+
diff --git a/native/Avalonia.Native/src/OSX/INSWindowHolder.h b/native/Avalonia.Native/src/OSX/INSWindowHolder.h
index adc0dd1990..ae64a53e7d 100644
--- a/native/Avalonia.Native/src/OSX/INSWindowHolder.h
+++ b/native/Avalonia.Native/src/OSX/INSWindowHolder.h
@@ -10,8 +10,8 @@
struct INSWindowHolder
{
- virtual AvnWindow* _Nonnull GetNSWindow () = 0;
- virtual AvnView* _Nonnull GetNSView () = 0;
+ virtual NSWindow* _Nonnull GetNSWindow () = 0;
+ virtual NSView* _Nonnull GetNSView () = 0;
};
#endif //AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H
diff --git a/native/Avalonia.Native/src/OSX/PopupImpl.h b/native/Avalonia.Native/src/OSX/PopupImpl.h
new file mode 100644
index 0000000000..451019a6a4
--- /dev/null
+++ b/native/Avalonia.Native/src/OSX/PopupImpl.h
@@ -0,0 +1,9 @@
+//
+// Created by Dan Walmsley on 06/05/2022.
+// Copyright (c) 2022 Avalonia. All rights reserved.
+//
+
+#ifndef AVALONIA_NATIVE_OSX_POPUPIMPL_H
+#define AVALONIA_NATIVE_OSX_POPUPIMPL_H
+
+#endif //AVALONIA_NATIVE_OSX_POPUPIMPL_H
diff --git a/native/Avalonia.Native/src/OSX/PopupImpl.mm b/native/Avalonia.Native/src/OSX/PopupImpl.mm
new file mode 100644
index 0000000000..3c5afd9424
--- /dev/null
+++ b/native/Avalonia.Native/src/OSX/PopupImpl.mm
@@ -0,0 +1,61 @@
+//
+// Created by Dan Walmsley on 06/05/2022.
+// Copyright (c) 2022 Avalonia. All rights reserved.
+//
+
+#include "WindowInterfaces.h"
+#include "AvnView.h"
+#include "WindowImpl.h"
+#include "automation.h"
+#include "menu.h"
+#include "common.h"
+#import "WindowBaseImpl.h"
+#import "WindowProtocol.h"
+#import
+#include "PopupImpl.h"
+
+class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup
+{
+private:
+ BEGIN_INTERFACE_MAP()
+ INHERIT_INTERFACE_MAP(WindowBaseImpl)
+ INTERFACE_MAP_ENTRY(IAvnPopup, IID_IAvnPopup)
+ END_INTERFACE_MAP()
+ virtual ~PopupImpl(){}
+ ComPtr WindowEvents;
+ PopupImpl(IAvnWindowEvents* events, IAvnGlContext* gl) : WindowBaseImpl(events, gl)
+ {
+ WindowEvents = events;
+ }
+protected:
+ virtual NSWindowStyleMask GetStyle() override
+ {
+ return NSWindowStyleMaskBorderless;
+ }
+
+ virtual void OnInitialiseNSWindow () override
+ {
+ [Window setLevel:NSPopUpMenuWindowLevel];
+ }
+
+public:
+ virtual bool ShouldTakeFocusOnShow() override
+ {
+ return false;
+ }
+
+ virtual HRESULT Show(bool activate, bool isDialog) override
+ {
+ return WindowBaseImpl::Show(activate, true);
+ }
+};
+
+
+extern IAvnPopup* CreateAvnPopup(IAvnWindowEvents*events, IAvnGlContext* gl)
+{
+ @autoreleasepool
+ {
+ IAvnPopup* ptr = dynamic_cast(new PopupImpl(events, gl));
+ return ptr;
+ }
+}
diff --git a/native/Avalonia.Native/src/OSX/ResizeScope.h b/native/Avalonia.Native/src/OSX/ResizeScope.h
index 7509f93c01..9a43c158fe 100644
--- a/native/Avalonia.Native/src/OSX/ResizeScope.h
+++ b/native/Avalonia.Native/src/OSX/ResizeScope.h
@@ -6,7 +6,6 @@
#ifndef AVALONIA_NATIVE_OSX_RESIZESCOPE_H
#define AVALONIA_NATIVE_OSX_RESIZESCOPE_H
-#include "window.h"
#include "avalonia-native.h"
@class AvnView;
diff --git a/native/Avalonia.Native/src/OSX/ResizeScope.mm b/native/Avalonia.Native/src/OSX/ResizeScope.mm
index 90e7f5cf15..9f1177af8b 100644
--- a/native/Avalonia.Native/src/OSX/ResizeScope.mm
+++ b/native/Avalonia.Native/src/OSX/ResizeScope.mm
@@ -5,7 +5,7 @@
#import
#include "ResizeScope.h"
-#import "AvnView.h"
+#include "AvnView.h"
ResizeScope::ResizeScope(AvnView *view, AvnPlatformResizeReason reason) {
_view = view;
diff --git a/native/Avalonia.Native/src/OSX/SystemDialogs.mm b/native/Avalonia.Native/src/OSX/SystemDialogs.mm
index 21ad9cfa7c..535b6c3b66 100644
--- a/native/Avalonia.Native/src/OSX/SystemDialogs.mm
+++ b/native/Avalonia.Native/src/OSX/SystemDialogs.mm
@@ -1,5 +1,4 @@
#include "common.h"
-#include "window.h"
#include "INSWindowHolder.h"
class SystemDialogs : public ComSingleObject
diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.h b/native/Avalonia.Native/src/OSX/WindowBaseImpl.h
index d2690cee41..83850e780c 100644
--- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.h
+++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.h
@@ -6,16 +6,16 @@
#ifndef AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
#define AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
-#import "rendertarget.h"
+#include "rendertarget.h"
#include "INSWindowHolder.h"
@class AutoFitContentView;
+@class AvnMenu;
+@protocol AvnWindowProtocol;
class WindowBaseImpl : public virtual ComObject,
public virtual IAvnWindowBase,
public INSWindowHolder {
-private:
- NSCursor *cursor;
public:
FORWARD_IUNKNOWN()
@@ -24,22 +24,7 @@ BEGIN_INTERFACE_MAP()
INTERFACE_MAP_ENTRY(IAvnWindowBase, IID_IAvnWindowBase)
END_INTERFACE_MAP()
- virtual ~WindowBaseImpl() {
- View = NULL;
- Window = NULL;
- }
-
- AutoFitContentView *StandardContainer;
- AvnView *View;
- AvnWindow *Window;
- ComPtr BaseEvents;
- ComPtr _glContext;
- NSObject *renderTarget;
- AvnPoint lastPositionSet;
- NSString *_lastTitle;
-
- bool _shown;
- bool _inResize;
+ virtual ~WindowBaseImpl();
WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl);
@@ -51,12 +36,14 @@ BEGIN_INTERFACE_MAP()
virtual HRESULT ObtainNSViewHandleRetained(void **ret) override;
- virtual AvnWindow *GetNSWindow() override;
+ virtual NSWindow *GetNSWindow() override;
- virtual AvnView *GetNSView() override;
+ virtual NSView *GetNSView() override;
virtual HRESULT Show(bool activate, bool isDialog) override;
+ virtual bool IsShown ();
+
virtual bool ShouldTakeFocusOnShow();
virtual HRESULT Hide() override;
@@ -111,11 +98,39 @@ BEGIN_INTERFACE_MAP()
virtual bool IsDialog();
+ id GetWindowProtocol ();
+
protected:
virtual NSWindowStyleMask GetStyle();
void UpdateStyle();
+
+ virtual void OnInitialiseNSWindow ();
+private:
+ void CreateNSWindow (bool isDialog);
+ void CleanNSWindow ();
+ void InitialiseNSWindow ();
+
+ NSCursor *cursor;
+ ComPtr _glContext;
+ bool hasPosition;
+ NSSize lastSize;
+ NSSize lastMinSize;
+ NSSize lastMaxSize;
+ AvnMenu* lastMenu;
+ bool _inResize;
+
+protected:
+ AvnPoint lastPositionSet;
+ AutoFitContentView *StandardContainer;
+ bool _shown;
+
+public:
+ NSObject *renderTarget;
+ NSWindow * Window;
+ ComPtr BaseEvents;
+ AvnView *View;
};
#endif //AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
index 43a27a34b2..022769bad0 100644
--- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
+++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
@@ -5,13 +5,21 @@
#import
#include "common.h"
-#import "window.h"
-#import "AvnView.h"
+#include "AvnView.h"
#include "menu.h"
#include "automation.h"
-#import "cursor.h"
+#include "cursor.h"
#include "ResizeScope.h"
-#import "AutoFitContentView.h"
+#include "AutoFitContentView.h"
+#import "WindowProtocol.h"
+#import "WindowInterfaces.h"
+#include "WindowBaseImpl.h"
+
+
+WindowBaseImpl::~WindowBaseImpl() {
+ View = nullptr;
+ Window = nullptr;
+}
WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl) {
_shown = false;
@@ -22,17 +30,14 @@ WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl)
View = [[AvnView alloc] initWithParent:this];
StandardContainer = [[AutoFitContentView new] initWithContent:View];
- Window = [[AvnWindow alloc] initWithParent:this];
- [Window setContentView:StandardContainer];
-
- lastPositionSet.X = 100;
- lastPositionSet.Y = 100;
- _lastTitle = @"";
+ lastPositionSet = { 0, 0 };
+ hasPosition = false;
+ lastSize = NSSize { 100, 100 };
+ lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX};
+ lastMinSize = NSSize { 0, 0 };
- [Window setStyleMask:NSWindowStyleMaskBorderless];
- [Window setBackingType:NSBackingStoreBuffered];
-
- [Window setOpaque:false];
+ Window = nullptr;
+ lastMenu = nullptr;
}
HRESULT WindowBaseImpl::ObtainNSViewHandle(void **ret) {
@@ -59,11 +64,11 @@ HRESULT WindowBaseImpl::ObtainNSViewHandleRetained(void **ret) {
return S_OK;
}
-AvnWindow *WindowBaseImpl::GetNSWindow() {
+NSWindow *WindowBaseImpl::GetNSWindow() {
return Window;
}
-AvnView *WindowBaseImpl::GetNSView() {
+NSView *WindowBaseImpl::GetNSView() {
return View;
}
@@ -83,10 +88,18 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
START_COM_CALL;
@autoreleasepool {
- SetPosition(lastPositionSet);
- UpdateStyle();
+ CreateNSWindow(isDialog);
+ InitialiseNSWindow();
+
+ if(hasPosition)
+ {
+ SetPosition(lastPositionSet);
+ } else
+ {
+ [Window center];
+ }
- [Window setTitle:_lastTitle];
+ UpdateStyle();
if (ShouldTakeFocusOnShow() && activate) {
[Window orderFront:Window];
@@ -103,6 +116,11 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
}
}
+bool WindowBaseImpl::IsShown ()
+{
+ return _shown;
+}
+
bool WindowBaseImpl::ShouldTakeFocusOnShow() {
return true;
}
@@ -125,7 +143,8 @@ HRESULT WindowBaseImpl::Hide() {
@autoreleasepool {
if (Window != nullptr) {
[Window orderOut:Window];
- [Window restoreParentWindow];
+
+ [GetWindowProtocol() restoreParentWindow];
}
return S_OK;
@@ -181,9 +200,8 @@ HRESULT WindowBaseImpl::GetClientSize(AvnSize *ret) {
if (ret == nullptr)
return E_POINTER;
- auto frame = [View frame];
- ret->Width = frame.size.width;
- ret->Height = frame.size.height;
+ ret->Width = lastSize.width;
+ ret->Height = lastSize.height;
return S_OK;
}
@@ -196,9 +214,11 @@ HRESULT WindowBaseImpl::GetFrameSize(AvnSize *ret) {
if (ret == nullptr)
return E_POINTER;
- auto frame = [Window frame];
- ret->Width = frame.size.width;
- ret->Height = frame.size.height;
+ if(Window != nullptr){
+ auto frame = [Window frame];
+ ret->Width = frame.size.width;
+ ret->Height = frame.size.height;
+ }
return S_OK;
}
@@ -225,8 +245,13 @@ HRESULT WindowBaseImpl::SetMinMaxSize(AvnSize minSize, AvnSize maxSize) {
START_COM_CALL;
@autoreleasepool {
- [Window setContentMinSize:ToNSSize(minSize)];
- [Window setContentMaxSize:ToNSSize(maxSize)];
+ lastMinSize = ToNSSize(minSize);
+ lastMaxSize = ToNSSize(maxSize);
+
+ if(Window != nullptr) {
+ [Window setContentMinSize:lastMinSize];
+ [Window setContentMaxSize:lastMaxSize];
+ }
return S_OK;
}
@@ -243,8 +268,8 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
auto resizeBlock = ResizeScope(View, reason);
@autoreleasepool {
- auto maxSize = [Window contentMaxSize];
- auto minSize = [Window contentMinSize];
+ auto maxSize = lastMaxSize;
+ auto minSize = lastMinSize;
if (x < minSize.width) {
x = minSize.width;
@@ -263,12 +288,15 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
}
@try {
+ lastSize = NSSize {x, y};
+
if (!_shown) {
BaseEvents->Resized(AvnSize{x, y}, reason);
}
- [Window setContentSize:NSSize{x, y}];
- [Window invalidateShadow];
+ if(Window != nullptr) {
+ [Window setContentSize:lastSize];
+ }
}
@finally {
_inResize = false;
@@ -293,12 +321,14 @@ HRESULT WindowBaseImpl::SetMainMenu(IAvnMenu *menu) {
auto nativeMenu = dynamic_cast(menu);
- auto nsmenu = nativeMenu->GetNative();
+ lastMenu = nativeMenu->GetNative();
- [Window applyMenu:nsmenu];
+ if(Window != nullptr) {
+ [GetWindowProtocol() applyMenu:lastMenu];
- if ([Window isKeyWindow]) {
- [Window showWindowMenuWithAppMenu];
+ if ([Window isKeyWindow]) {
+ [GetWindowProtocol() showWindowMenuWithAppMenu];
+ }
}
return S_OK;
@@ -334,12 +364,17 @@ HRESULT WindowBaseImpl::GetPosition(AvnPoint *ret) {
return E_POINTER;
}
- auto frame = [Window frame];
+ if(Window != nullptr) {
+ auto frame = [Window frame];
- ret->X = frame.origin.x;
- ret->Y = frame.origin.y + frame.size.height;
+ ret->X = frame.origin.x;
+ ret->Y = frame.origin.y + frame.size.height;
- *ret = ConvertPointY(*ret);
+ *ret = ConvertPointY(*ret);
+ } else
+ {
+ *ret = lastPositionSet;
+ }
return S_OK;
}
@@ -350,7 +385,11 @@ HRESULT WindowBaseImpl::SetPosition(AvnPoint point) {
@autoreleasepool {
lastPositionSet = point;
- [Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(point))];
+ hasPosition = true;
+
+ if(Window != nullptr) {
+ [Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(point))];
+ }
return S_OK;
}
@@ -502,4 +541,75 @@ NSWindowStyleMask WindowBaseImpl::GetStyle() {
void WindowBaseImpl::UpdateStyle() {
[Window setStyleMask:GetStyle()];
-}
\ No newline at end of file
+}
+
+void WindowBaseImpl::CleanNSWindow() {
+ if(Window != nullptr) {
+ [GetWindowProtocol() disconnectParent];
+ [Window close];
+ Window = nullptr;
+ }
+}
+
+void WindowBaseImpl::CreateNSWindow(bool isDialog) {
+ if (isDialog) {
+ if (![Window isKindOfClass:[AvnPanel class]]) {
+ CleanNSWindow();
+
+ Window = [[AvnPanel alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:GetStyle()];
+ }
+ } else {
+ if (![Window isKindOfClass:[AvnWindow class]]) {
+ CleanNSWindow();
+
+ Window = [[AvnWindow alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:GetStyle()];
+ }
+ }
+}
+
+void WindowBaseImpl::OnInitialiseNSWindow()
+{
+
+}
+
+void WindowBaseImpl::InitialiseNSWindow() {
+ if(Window != nullptr) {
+ [Window setContentView:StandardContainer];
+ [Window setStyleMask:NSWindowStyleMaskBorderless];
+ [Window setBackingType:NSBackingStoreBuffered];
+
+ [Window setContentSize:lastSize];
+ [Window setContentMinSize:lastMinSize];
+ [Window setContentMaxSize:lastMaxSize];
+
+ [Window setOpaque:false];
+
+ if (lastMenu != nullptr) {
+ [GetWindowProtocol() applyMenu:lastMenu];
+
+ if ([Window isKeyWindow]) {
+ [GetWindowProtocol() showWindowMenuWithAppMenu];
+ }
+ }
+
+ OnInitialiseNSWindow();
+ }
+}
+
+id WindowBaseImpl::GetWindowProtocol() {
+ if(Window == nullptr)
+ {
+ return nullptr;
+ }
+
+ return (id ) Window;
+}
+
+extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events, IAvnGlContext* gl)
+{
+ @autoreleasepool
+ {
+ IAvnWindow* ptr = (IAvnWindow*)new WindowImpl(events, gl);
+ return ptr;
+ }
+}
diff --git a/native/Avalonia.Native/src/OSX/WindowImpl.h b/native/Avalonia.Native/src/OSX/WindowImpl.h
index b229921baa..db19497b29 100644
--- a/native/Avalonia.Native/src/OSX/WindowImpl.h
+++ b/native/Avalonia.Native/src/OSX/WindowImpl.h
@@ -6,7 +6,6 @@
#ifndef AVALONIA_NATIVE_OSX_WINDOWIMPL_H
#define AVALONIA_NATIVE_OSX_WINDOWIMPL_H
-
#import "WindowBaseImpl.h"
#include "IWindowStateChanged.h"
@@ -89,9 +88,14 @@ BEGIN_INTERFACE_MAP()
virtual HRESULT SetWindowState (AvnWindowState state) override;
virtual bool IsDialog() override;
+
+ virtual void OnInitialiseNSWindow() override;
protected:
virtual NSWindowStyleMask GetStyle() override;
+
+private:
+ NSString *_lastTitle;
};
#endif //AVALONIA_NATIVE_OSX_WINDOWIMPL_H
diff --git a/native/Avalonia.Native/src/OSX/WindowImpl.mm b/native/Avalonia.Native/src/OSX/WindowImpl.mm
index 0d325c4490..d43a8beee4 100644
--- a/native/Avalonia.Native/src/OSX/WindowImpl.mm
+++ b/native/Avalonia.Native/src/OSX/WindowImpl.mm
@@ -4,10 +4,10 @@
//
#import
-#import "window.h"
-#import "AutoFitContentView.h"
-#import "AvnView.h"
+#include "AutoFitContentView.h"
+#include "AvnView.h"
#include "automation.h"
+#include "WindowProtocol.h"
WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBaseImpl(events, gl) {
_isClientAreaExtended = false;
@@ -19,11 +19,8 @@ WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBase
_inSetWindowState = false;
_lastWindowState = Normal;
_actualWindowState = Normal;
+ _lastTitle = @"";
WindowEvents = events;
- [Window setCanBecomeKeyAndMain];
- [Window disableCursorRects];
- [Window setTabbingMode:NSWindowTabbingModeDisallowed];
- [Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
}
void WindowImpl::HideOrShowTrafficLights() {
@@ -51,11 +48,27 @@ void WindowImpl::HideOrShowTrafficLights() {
}
}
+void WindowImpl::OnInitialiseNSWindow(){
+ [GetWindowProtocol() setCanBecomeKeyWindow:true];
+ [Window disableCursorRects];
+ [Window setTabbingMode:NSWindowTabbingModeDisallowed];
+ [Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+
+ [Window setTitle:_lastTitle];
+
+ if(_isClientAreaExtended)
+ {
+ [GetWindowProtocol() setIsExtended:true];
+ SetExtendClientArea(true);
+ }
+}
+
HRESULT WindowImpl::Show(bool activate, bool isDialog) {
START_COM_CALL;
@autoreleasepool {
_isDialog = isDialog;
+
WindowBaseImpl::Show(activate, isDialog);
HideOrShowTrafficLights();
@@ -68,7 +81,7 @@ HRESULT WindowImpl::SetEnabled(bool enable) {
START_COM_CALL;
@autoreleasepool {
- [Window setEnabled:enable];
+ [GetWindowProtocol() setEnabled:enable];
return S_OK;
}
}
@@ -328,37 +341,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;
- }
- [Window setIsExtended:enable];
+ [GetWindowProtocol() setIsExtended:enable];
- HideOrShowTrafficLights();
+ HideOrShowTrafficLights();
- UpdateStyle();
+ UpdateStyle();
+ }
return S_OK;
}
@@ -383,7 +398,7 @@ HRESULT WindowImpl::GetExtendTitleBarHeight(double *ret) {
return E_POINTER;
}
- *ret = [Window getExtendedTitleBarHeight];
+ *ret = [GetWindowProtocol() getExtendedTitleBarHeight];
return S_OK;
}
@@ -417,6 +432,9 @@ HRESULT WindowImpl::SetWindowState(AvnWindowState state) {
START_COM_CALL;
@autoreleasepool {
+ auto currentState = _actualWindowState;
+ _lastWindowState = state;
+
if (Window == nullptr) {
return S_OK;
}
@@ -427,9 +445,6 @@ HRESULT WindowImpl::SetWindowState(AvnWindowState state) {
_inSetWindowState = true;
- auto currentState = _actualWindowState;
- _lastWindowState = state;
-
if (currentState == Normal) {
_preZoomSize = [Window frame];
}
@@ -508,7 +523,7 @@ bool WindowImpl::IsDialog() {
}
NSWindowStyleMask WindowImpl::GetStyle() {
- unsigned long s = NSWindowStyleMaskBorderless;
+ unsigned long s = this->_isDialog ? NSWindowStyleMaskUtilityWindow : NSWindowStyleMaskBorderless;
switch (_decorations) {
case SystemDecorationsNone:
diff --git a/native/Avalonia.Native/src/OSX/WindowInterfaces.h b/native/Avalonia.Native/src/OSX/WindowInterfaces.h
new file mode 100644
index 0000000000..6e6d62e85e
--- /dev/null
+++ b/native/Avalonia.Native/src/OSX/WindowInterfaces.h
@@ -0,0 +1,17 @@
+//
+// Created by Dan Walmsley on 06/05/2022.
+// Copyright (c) 2022 Avalonia. All rights reserved.
+//
+
+#import
+#import
+#include "WindowProtocol.h"
+#include "WindowBaseImpl.h"
+
+@interface AvnWindow : NSWindow
+-(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask;
+@end
+
+@interface AvnPanel : NSPanel
+-(AvnPanel* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask;
+@end
\ No newline at end of file
diff --git a/native/Avalonia.Native/src/OSX/window.h b/native/Avalonia.Native/src/OSX/WindowProtocol.h
similarity index 59%
rename from native/Avalonia.Native/src/OSX/window.h
rename to native/Avalonia.Native/src/OSX/WindowProtocol.h
index e9b98ce9ae..0e5c5869e7 100644
--- a/native/Avalonia.Native/src/OSX/window.h
+++ b/native/Avalonia.Native/src/OSX/WindowProtocol.h
@@ -1,15 +1,15 @@
-#ifndef window_h
-#define window_h
+//
+// Created by Dan Walmsley on 06/05/2022.
+// Copyright (c) 2022 Avalonia. All rights reserved.
+//
-#import "avalonia-native.h"
+#pragma once
-@class AvnMenu;
+#import
-class WindowBaseImpl;
+@class AvnMenu;
-@interface AvnWindow : NSWindow
--(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
--(void) setCanBecomeKeyAndMain;
+@protocol AvnWindowProtocol
-(void) pollModalSession: (NSModalSession _Nonnull) session;
-(void) restoreParentWindow;
-(bool) shouldTryToHandleEvents;
@@ -20,7 +20,8 @@ class WindowBaseImpl;
-(double) getExtendedTitleBarHeight;
-(void) setIsExtended:(bool)value;
+-(void) disconnectParent;
-(bool) isDialog;
-@end
-#endif /* window_h */
+-(void) setCanBecomeKeyWindow:(bool)value;
+@end
diff --git a/native/Avalonia.Native/src/OSX/automation.h b/native/Avalonia.Native/src/OSX/automation.h
index 1727d21f27..367df3619d 100644
--- a/native/Avalonia.Native/src/OSX/automation.h
+++ b/native/Avalonia.Native/src/OSX/automation.h
@@ -1,5 +1,6 @@
-#import
+#pragma once
+#import
NS_ASSUME_NONNULL_BEGIN
class IAvnAutomationPeer;
diff --git a/native/Avalonia.Native/src/OSX/automation.mm b/native/Avalonia.Native/src/OSX/automation.mm
index 7a0b3b8127..d0c8d7a9db 100644
--- a/native/Avalonia.Native/src/OSX/automation.mm
+++ b/native/Avalonia.Native/src/OSX/automation.mm
@@ -1,9 +1,8 @@
#include "common.h"
-#import "automation.h"
-#import "window.h"
+#include "automation.h"
#include "AvnString.h"
-#import "INSWindowHolder.h"
-#import "AvnView.h"
+#include "INSWindowHolder.h"
+#include "AvnView.h"
@interface AvnAccessibilityElement (Events)
- (void) raiseChildrenChanged;
diff --git a/native/Avalonia.Native/src/OSX/main.mm b/native/Avalonia.Native/src/OSX/main.mm
index 011f881e94..6ee86b21ae 100644
--- a/native/Avalonia.Native/src/OSX/main.mm
+++ b/native/Avalonia.Native/src/OSX/main.mm
@@ -1,7 +1,6 @@
//This file will contain actual IID structures
#define COM_GUIDS_MATERIALIZE
#include "common.h"
-#include "window.h"
static NSString* s_appTitle = @"Avalonia";
diff --git a/native/Avalonia.Native/src/OSX/menu.mm b/native/Avalonia.Native/src/OSX/menu.mm
index fd74edd772..b05588a441 100644
--- a/native/Avalonia.Native/src/OSX/menu.mm
+++ b/native/Avalonia.Native/src/OSX/menu.mm
@@ -1,7 +1,6 @@
#include "common.h"
#include "menu.h"
-#import "window.h"
#include "KeyTransform.h"
#include
#include /* For kVK_ constants, and TIS functions. */
diff --git a/samples/BindingDemo/BindingDemo.csproj b/samples/BindingDemo/BindingDemo.csproj
index 2c6ff74e5e..bd6054327f 100644
--- a/samples/BindingDemo/BindingDemo.csproj
+++ b/samples/BindingDemo/BindingDemo.csproj
@@ -5,6 +5,7 @@
+
diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj
index 7cbd8a3f9c..e5f07c90c3 100644
--- a/samples/ControlCatalog/ControlCatalog.csproj
+++ b/samples/ControlCatalog/ControlCatalog.csproj
@@ -25,6 +25,8 @@
+
+
diff --git a/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml b/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml
index 2fe16ba8e3..aef96802f4 100644
--- a/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml
+++ b/samples/ControlCatalog/Pages/CalendarDatePickerPage.xaml
@@ -10,8 +10,7 @@
Margin="0,16,0,0"
HorizontalAlignment="Center"
Spacing="16">
-
+
+
diff --git a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
index 2b0c30f311..c44024d952 100644
--- a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
+++ b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
@@ -18,7 +18,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;
diff --git a/samples/IntegrationTestApp/IntegrationTestApp.csproj b/samples/IntegrationTestApp/IntegrationTestApp.csproj
index e8338adae6..4284399357 100644
--- a/samples/IntegrationTestApp/IntegrationTestApp.csproj
+++ b/samples/IntegrationTestApp/IntegrationTestApp.csproj
@@ -1,4 +1,4 @@
-
+
WinExe
net6.0
@@ -18,6 +18,7 @@
+
diff --git a/samples/PlatformSanityChecks/PlatformSanityChecks.csproj b/samples/PlatformSanityChecks/PlatformSanityChecks.csproj
index 9660d2a90d..4f7f06b529 100644
--- a/samples/PlatformSanityChecks/PlatformSanityChecks.csproj
+++ b/samples/PlatformSanityChecks/PlatformSanityChecks.csproj
@@ -7,6 +7,7 @@
+
diff --git a/samples/Previewer/Previewer.csproj b/samples/Previewer/Previewer.csproj
index c1d14cba26..98560e9ab0 100644
--- a/samples/Previewer/Previewer.csproj
+++ b/samples/Previewer/Previewer.csproj
@@ -9,6 +9,9 @@
+
+
+
diff --git a/samples/RenderDemo/RenderDemo.csproj b/samples/RenderDemo/RenderDemo.csproj
index 18a4ee5662..3c62af1eaf 100644
--- a/samples/RenderDemo/RenderDemo.csproj
+++ b/samples/RenderDemo/RenderDemo.csproj
@@ -12,6 +12,7 @@
+
diff --git a/samples/Sandbox/Sandbox.csproj b/samples/Sandbox/Sandbox.csproj
index f3c38cd96e..eab654acb6 100644
--- a/samples/Sandbox/Sandbox.csproj
+++ b/samples/Sandbox/Sandbox.csproj
@@ -10,6 +10,7 @@
+
diff --git a/samples/VirtualizationDemo/VirtualizationDemo.csproj b/samples/VirtualizationDemo/VirtualizationDemo.csproj
index 2c6ff74e5e..bd6054327f 100644
--- a/samples/VirtualizationDemo/VirtualizationDemo.csproj
+++ b/samples/VirtualizationDemo/VirtualizationDemo.csproj
@@ -5,6 +5,7 @@
+
diff --git a/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj b/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj
index cd9963a2e5..81b94b4d09 100644
--- a/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj
+++ b/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj
@@ -22,6 +22,7 @@
+
diff --git a/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj b/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj
index c25442b52c..2f3ea85e46 100644
--- a/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj
+++ b/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj
@@ -9,6 +9,7 @@
+
diff --git a/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs b/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
index 8a475676a5..65a9adc937 100644
--- a/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
+++ b/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
@@ -40,7 +40,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
_gl = GlPlatformSurface.TryCreate(this);
_framebuffer = new FramebufferManager(this);
- RenderScaling = (int)_view.Scaling;
+ RenderScaling = _view.Scaling;
MaxClientSize = new PixelSize(_view.Resources.DisplayMetrics.WidthPixels,
_view.Resources.DisplayMetrics.HeightPixels).ToSize(RenderScaling);
diff --git a/src/Avalonia.Base/Animation/IAnimation.cs b/src/Avalonia.Base/Animation/IAnimation.cs
index 436a765d27..eda86ed106 100644
--- a/src/Avalonia.Base/Animation/IAnimation.cs
+++ b/src/Avalonia.Base/Animation/IAnimation.cs
@@ -1,12 +1,14 @@
using System;
using System.Threading;
using System.Threading.Tasks;
+using Avalonia.Metadata;
namespace Avalonia.Animation
{
///
/// Interface for Animation objects
///
+ [NotClientImplementable]
public interface IAnimation
{
///
diff --git a/src/Avalonia.Base/Animation/IAnimationSetter.cs b/src/Avalonia.Base/Animation/IAnimationSetter.cs
index 6a1d3539e2..8c4ba95517 100644
--- a/src/Avalonia.Base/Animation/IAnimationSetter.cs
+++ b/src/Avalonia.Base/Animation/IAnimationSetter.cs
@@ -1,5 +1,8 @@
+using Avalonia.Metadata;
+
namespace Avalonia.Animation
{
+ [NotClientImplementable]
public interface IAnimationSetter
{
AvaloniaProperty? Property { get; set; }
diff --git a/src/Avalonia.Base/Animation/IAnimator.cs b/src/Avalonia.Base/Animation/IAnimator.cs
index f64ac9f913..06ba8dc329 100644
--- a/src/Avalonia.Base/Animation/IAnimator.cs
+++ b/src/Avalonia.Base/Animation/IAnimator.cs
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
+using Avalonia.Metadata;
namespace Avalonia.Animation
{
///
/// Interface for Animator objects
///
+ [NotClientImplementable]
public interface IAnimator : IList
{
///
diff --git a/src/Avalonia.Base/Animation/IClock.cs b/src/Avalonia.Base/Animation/IClock.cs
index ae44102077..7b3b7b3924 100644
--- a/src/Avalonia.Base/Animation/IClock.cs
+++ b/src/Avalonia.Base/Animation/IClock.cs
@@ -1,9 +1,9 @@
using System;
-using System.Collections.Generic;
-using System.Text;
+using Avalonia.Metadata;
namespace Avalonia.Animation
{
+ [NotClientImplementable]
public interface IClock : IObservable
{
PlayState PlayState { get; set; }
diff --git a/src/Avalonia.Base/Animation/IGlobalClock.cs b/src/Avalonia.Base/Animation/IGlobalClock.cs
index b0455e2c80..138dc07539 100644
--- a/src/Avalonia.Base/Animation/IGlobalClock.cs
+++ b/src/Avalonia.Base/Animation/IGlobalClock.cs
@@ -1,9 +1,8 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
+using Avalonia.Metadata;
namespace Avalonia.Animation
{
+ [NotClientImplementable]
public interface IGlobalClock : IClock
{
}
diff --git a/src/Avalonia.Base/Animation/ITransition.cs b/src/Avalonia.Base/Animation/ITransition.cs
index 241ca208d1..639b92ce35 100644
--- a/src/Avalonia.Base/Animation/ITransition.cs
+++ b/src/Avalonia.Base/Animation/ITransition.cs
@@ -1,10 +1,12 @@
using System;
+using Avalonia.Metadata;
namespace Avalonia.Animation
{
///
/// Interface for Transition objects.
///
+ [NotClientImplementable]
public interface ITransition
{
///
diff --git a/src/Avalonia.Base/Collections/AvaloniaList.cs b/src/Avalonia.Base/Collections/AvaloniaList.cs
index 9972e72dd4..a05c9c5da3 100644
--- a/src/Avalonia.Base/Collections/AvaloniaList.cs
+++ b/src/Avalonia.Base/Collections/AvaloniaList.cs
@@ -394,7 +394,13 @@ namespace Avalonia.Collections
} while (en.MoveNext());
if (notificationItems is not null)
+ {
NotifyAdd(notificationItems, index);
+ }
+ else
+ {
+ NotifyCountChanged();
+ }
}
}
}
diff --git a/src/Avalonia.Base/Controls/INameScope.cs b/src/Avalonia.Base/Controls/INameScope.cs
index 1ca7db2f37..a12e88c055 100644
--- a/src/Avalonia.Base/Controls/INameScope.cs
+++ b/src/Avalonia.Base/Controls/INameScope.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Threading.Tasks;
+using Avalonia.Metadata;
using Avalonia.Utilities;
namespace Avalonia.Controls
@@ -7,6 +6,7 @@ namespace Avalonia.Controls
///
/// Defines a name scope.
///
+ [NotClientImplementable]
public interface INameScope
{
///
diff --git a/src/Avalonia.Base/Controls/IPseudoClasses.cs b/src/Avalonia.Base/Controls/IPseudoClasses.cs
index 27290716d0..eda521727f 100644
--- a/src/Avalonia.Base/Controls/IPseudoClasses.cs
+++ b/src/Avalonia.Base/Controls/IPseudoClasses.cs
@@ -1,9 +1,11 @@
+using Avalonia.Metadata;
namespace Avalonia.Controls
{
///
/// Exposes an interface for setting pseudoclasses on a collection.
///
+ [NotClientImplementable]
public interface IPseudoClasses
{
///
diff --git a/src/Avalonia.Base/Controls/IResourceHost.cs b/src/Avalonia.Base/Controls/IResourceHost.cs
index ea34a8b39a..286f0e36ef 100644
--- a/src/Avalonia.Base/Controls/IResourceHost.cs
+++ b/src/Avalonia.Base/Controls/IResourceHost.cs
@@ -1,6 +1,5 @@
using System;
-
-#nullable enable
+using Avalonia.Metadata;
namespace Avalonia.Controls
{
@@ -10,6 +9,7 @@ namespace Avalonia.Controls
///
/// This interface is implemented by and `Application`.
///
+ [NotClientImplementable]
public interface IResourceHost : IResourceNode
{
///
diff --git a/src/Avalonia.Base/Controls/IResourceNode.cs b/src/Avalonia.Base/Controls/IResourceNode.cs
index 73bfeaf161..d6c900f97f 100644
--- a/src/Avalonia.Base/Controls/IResourceNode.cs
+++ b/src/Avalonia.Base/Controls/IResourceNode.cs
@@ -1,6 +1,5 @@
using System;
-
-#nullable enable
+using Avalonia.Metadata;
namespace Avalonia.Controls
{
@@ -12,6 +11,7 @@ namespace Avalonia.Controls
/// () and resource providers such as
/// (see ).
///
+ [NotClientImplementable]
public interface IResourceNode
{
///
diff --git a/src/Avalonia.Base/Controls/ISetInheritanceParent.cs b/src/Avalonia.Base/Controls/ISetInheritanceParent.cs
index dbf8c68892..e85e025005 100644
--- a/src/Avalonia.Base/Controls/ISetInheritanceParent.cs
+++ b/src/Avalonia.Base/Controls/ISetInheritanceParent.cs
@@ -1,4 +1,4 @@
-#nullable enable
+using Avalonia.Metadata;
namespace Avalonia.Controls
{
@@ -10,6 +10,7 @@ namespace Avalonia.Controls
/// Additionally, also sets the inheritance parent; this
/// interface is only needed where the logical and inheritance parents differ.
///
+ [NotClientImplementable]
public interface ISetInheritanceParent
{
///
diff --git a/src/Avalonia.Base/Controls/ISetLogicalParent.cs b/src/Avalonia.Base/Controls/ISetLogicalParent.cs
index 85bda05961..7f1b4b5d87 100644
--- a/src/Avalonia.Base/Controls/ISetLogicalParent.cs
+++ b/src/Avalonia.Base/Controls/ISetLogicalParent.cs
@@ -1,6 +1,5 @@
using Avalonia.LogicalTree;
-
-#nullable enable
+using Avalonia.Metadata;
namespace Avalonia.Controls
{
@@ -10,6 +9,7 @@ namespace Avalonia.Controls
///
/// You should not usually need to use this interface - it is for advanced scenarios only.
///
+ [NotClientImplementable]
public interface ISetLogicalParent
{
///
diff --git a/src/Avalonia.Base/Data/Core/ExpressionNode.cs b/src/Avalonia.Base/Data/Core/ExpressionNode.cs
index 54785f18e8..4f755ff140 100644
--- a/src/Avalonia.Base/Data/Core/ExpressionNode.cs
+++ b/src/Avalonia.Base/Data/Core/ExpressionNode.cs
@@ -98,36 +98,36 @@ namespace Avalonia.Data.Core
private void ValueChanged(object? value, bool notify)
{
- if (_subscriber is null)
- return;
-
- var notification = value as BindingNotification;
-
- if (notification == null)
+ if (_subscriber is { } subscriber)
{
- LastValue = value != null ? new WeakReference