From dbe8f748c963f201d398da7bd9b4f44c97b5d046 Mon Sep 17 00:00:00 2001 From: WojciechKrysiak Date: Mon, 13 Aug 2018 20:46:22 +0200 Subject: [PATCH] Single menu context menus working. (#1808) --- src/OSX/Avalonia.MonoMac/PopupImpl.cs | 14 +++++++++++++- src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs | 16 ++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/OSX/Avalonia.MonoMac/PopupImpl.cs b/src/OSX/Avalonia.MonoMac/PopupImpl.cs index ba4b7f0eac..267e47a6a0 100644 --- a/src/OSX/Avalonia.MonoMac/PopupImpl.cs +++ b/src/OSX/Avalonia.MonoMac/PopupImpl.cs @@ -8,11 +8,23 @@ namespace Avalonia.MonoMac public PopupImpl() { UpdateStyle(); + Window.Level = NSWindowLevel.PopUpMenu; } protected override NSWindowStyle GetStyle() { return NSWindowStyle.Borderless; } + + protected override CustomWindow CreateCustomWindow() => new CustomPopupWindow(this); + + private class CustomPopupWindow : CustomWindow + { + public CustomPopupWindow(WindowBaseImpl impl) + : base(impl) + { } + + public override bool WorksWhenModal() => true; + } } -} \ No newline at end of file +} diff --git a/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs b/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs index e7d82ae25e..d3053a6af1 100644 --- a/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs +++ b/src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs @@ -19,14 +19,13 @@ namespace Avalonia.MonoMac public WindowBaseImpl() { _managedDrag = new ManagedWindowResizeDragHelper(this, _ => { }, ResizeForManagedDrag); - Window = new CustomWindow(this) - { - StyleMask = NSWindowStyle.Titled, - BackingType = NSBackingStore.Buffered, - ContentView = View, - // ReSharper disable once VirtualMemberCallInConstructor - Delegate = CreateWindowDelegate() - }; + // ReSharper disable once VirtualMemberCallInConstructor + Window = CreateCustomWindow(); + Window.StyleMask = NSWindowStyle.Titled; + Window.BackingType = NSBackingStore.Buffered; + Window.ContentView = View; + // ReSharper disable once VirtualMemberCallInConstructor + Window.Delegate = CreateWindowDelegate(); } public class CustomWindow : NSWindow @@ -57,6 +56,7 @@ namespace Avalonia.MonoMac public void SetCanBecomeKeyAndMain() => _canBecomeKeyAndMain = true; } + protected virtual CustomWindow CreateCustomWindow() => new CustomWindow(this); protected virtual NSWindowDelegate CreateWindowDelegate() => new WindowBaseDelegate(this); public class WindowBaseDelegate : NSWindowDelegate