Browse Source

Merge branch 'master' into feature/web-copy-paste-text

pull/8242/head
Max Katz 4 years ago
committed by GitHub
parent
commit
7f3bf01dc0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      native/Avalonia.Native/src/OSX/AvnPanelWindow.mm
  2. 4
      native/Avalonia.Native/src/OSX/AvnView.mm
  3. 81
      native/Avalonia.Native/src/OSX/AvnWindow.mm
  4. 2
      native/Avalonia.Native/src/OSX/INSWindowHolder.h
  5. 6
      native/Avalonia.Native/src/OSX/WindowBaseImpl.h
  6. 19
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
  7. 7
      native/Avalonia.Native/src/OSX/WindowImpl.h
  8. 107
      native/Avalonia.Native/src/OSX/WindowImpl.mm
  9. 1
      native/Avalonia.Native/src/OSX/WindowProtocol.h
  10. 2
      samples/ControlCatalog/Pages/DialogsPage.xaml
  11. 13
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  12. 9
      src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs
  13. 5
      src/Avalonia.Controls/ContextMenu.cs
  14. 3
      src/Avalonia.Controls/Flyouts/FlyoutBase.cs
  15. 21
      tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
  16. 25
      tests/Avalonia.Controls.UnitTests/FlyoutTests.cs
  17. 32
      tests/Avalonia.Markup.UnitTests/Data/BindingTests_Method.cs

2
native/Avalonia.Native/src/OSX/AvnPanelWindow.mm

@ -3,8 +3,6 @@
// Copyright (c) 2022 Avalonia. All rights reserved. // Copyright (c) 2022 Avalonia. All rights reserved.
// //
#pragma once
#define IS_NSPANEL #define IS_NSPANEL
#include "AvnWindow.mm" #include "AvnWindow.mm"

4
native/Avalonia.Native/src/OSX/AvnView.mm

@ -222,7 +222,7 @@
- (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type - (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type
{ {
bool triggerInputWhenDisabled = type != Move; bool triggerInputWhenDisabled = type != Move && type != LeaveWindow;
if([self ignoreUserInput: triggerInputWhenDisabled]) if([self ignoreUserInput: triggerInputWhenDisabled])
{ {
@ -709,4 +709,4 @@
return [[self accessibilityChild] accessibilityFocusedUIElement]; return [[self accessibilityChild] accessibilityFocusedUIElement];
} }
@end @end

81
native/Avalonia.Native/src/OSX/AvnWindow.mm

@ -68,7 +68,7 @@
} }
} }
- (void)performClose:(id)sender - (void)performClose:(id _Nullable )sender
{ {
if([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) if([[self delegate] respondsToSelector:@selector(windowShouldClose:)])
{ {
@ -147,7 +147,7 @@
} }
} }
-(void) applyMenu:(AvnMenu *)menu -(void) applyMenu:(AvnMenu *_Nullable)menu
{ {
if(menu == nullptr) if(menu == nullptr)
{ {
@ -157,7 +157,7 @@
_menu = menu; _menu = menu;
} }
-(CLASS_NAME*) initWithParent: (WindowBaseImpl*) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask; -(CLASS_NAME*_Nonnull) initWithParent: (WindowBaseImpl*_Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask;
{ {
// https://jameshfisher.com/2020/07/10/why-is-the-contentrect-of-my-nswindow-ignored/ // 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 // create nswindow with specific contentRect, otherwise we wont be able to resize the window
@ -176,14 +176,15 @@
_isExtended = false; _isExtended = false;
#ifdef IS_NSPANEL if(self.isDialog)
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary]; {
#endif [self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
}
return self; return self;
} }
- (BOOL)windowShouldClose:(NSWindow *)sender - (BOOL)windowShouldClose:(NSWindow *_Nonnull)sender
{ {
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw()); auto window = dynamic_cast<WindowImpl*>(_parent.getRaw());
@ -195,21 +196,28 @@
return true; return true;
} }
- (void)windowDidChangeBackingProperties:(NSNotification *)notification - (void)windowDidChangeBackingProperties:(NSNotification *_Nonnull)notification
{ {
[self backingScaleFactor]; [self backingScaleFactor];
} }
- (void)windowWillClose:(NSNotification *)notification - (void)windowWillClose:(NSNotification *_Nonnull)notification
{ {
_closed = true; _closed = true;
if(_parent) if(_parent)
{ {
ComPtr<WindowBaseImpl> parent = _parent; ComPtr<WindowBaseImpl> parent = _parent;
_parent = NULL; _parent = NULL;
[self restoreParentWindow];
auto window = dynamic_cast<WindowImpl*>(parent.getRaw());
if(window != nullptr)
{
window->SetParent(nullptr);
}
parent->BaseEvents->Closed(); parent->BaseEvents->Closed();
[parent->View onClosed]; [parent->View onClosed];
} }
@ -220,17 +228,11 @@
if(_canBecomeKeyWindow) if(_canBecomeKeyWindow)
{ {
// If the window has a child window being shown as a dialog then don't allow it to become the key window. // 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 parent = dynamic_cast<WindowImpl*>(_parent.getRaw());
if(parent != nullptr)
{ {
if (![uch conformsToProtocol:@protocol(AvnWindowProtocol)]) return parent->CanBecomeKeyWindow();
{
continue;
}
id <AvnWindowProtocol> ch = (id <AvnWindowProtocol>) uch;
if(ch.isDialog)
return false;
} }
return true; return true;
@ -259,6 +261,10 @@
-(void) setEnabled:(bool)enable -(void) setEnabled:(bool)enable
{ {
_isEnabled = enable; _isEnabled = enable;
[[self standardWindowButton:NSWindowCloseButton] setEnabled:enable];
[[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled:enable];
[[self standardWindowButton:NSWindowZoomButton] setEnabled:enable];
} }
-(void)becomeKeyWindow -(void)becomeKeyWindow
@ -273,17 +279,12 @@
[super becomeKeyWindow]; [super becomeKeyWindow];
} }
-(void) restoreParentWindow; - (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification
{ {
auto parent = [self parentWindow]; _parent->BringToFront();
if(parent != nil)
{
[parent removeChildWindow:self];
}
} }
- (void)windowDidMiniaturize:(NSNotification *)notification - (void)windowDidMiniaturize:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -293,7 +294,7 @@
} }
} }
- (void)windowDidDeminiaturize:(NSNotification *)notification - (void)windowDidDeminiaturize:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -303,7 +304,7 @@
} }
} }
- (void)windowDidResize:(NSNotification *)notification - (void)windowDidResize:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -313,7 +314,7 @@
} }
} }
- (void)windowWillExitFullScreen:(NSNotification *)notification - (void)windowWillExitFullScreen:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -323,7 +324,7 @@
} }
} }
- (void)windowDidExitFullScreen:(NSNotification *)notification - (void)windowDidExitFullScreen:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -346,7 +347,7 @@
} }
} }
- (void)windowWillEnterFullScreen:(NSNotification *)notification - (void)windowWillEnterFullScreen:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -356,7 +357,7 @@
} }
} }
- (void)windowDidEnterFullScreen:(NSNotification *)notification - (void)windowDidEnterFullScreen:(NSNotification *_Nonnull)notification
{ {
auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->()); auto parent = dynamic_cast<IWindowStateChanged*>(_parent.operator->());
@ -367,7 +368,7 @@
} }
} }
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame - (BOOL)windowShouldZoom:(NSWindow *_Nonnull)window toFrame:(NSRect)newFrame
{ {
return true; return true;
} }
@ -378,11 +379,13 @@
_parent->BaseEvents->Deactivated(); _parent->BaseEvents->Deactivated();
[self showAppMenuOnly]; [self showAppMenuOnly];
[self invalidateShadow];
[super resignKeyWindow]; [super resignKeyWindow];
} }
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *_Nonnull)notification
{ {
AvnPoint position; AvnPoint position;
@ -414,7 +417,7 @@
return pt; return pt;
} }
- (void)sendEvent:(NSEvent *)event - (void)sendEvent:(NSEvent *_Nonnull)event
{ {
[super sendEvent:event]; [super sendEvent:event];
@ -437,8 +440,10 @@
_parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast<uint32>([event timestamp] * 1000), AvnInputModifiersNone, point, delta); _parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast<uint32>([event timestamp] * 1000), AvnInputModifiersNone, point, delta);
} }
_parent->BringToFront();
} }
break; break;
case NSEventTypeMouseEntered: case NSEventTypeMouseEntered:
{ {

2
native/Avalonia.Native/src/OSX/INSWindowHolder.h

@ -11,7 +11,7 @@
struct INSWindowHolder struct INSWindowHolder
{ {
virtual NSWindow* _Nonnull GetNSWindow () = 0; virtual NSWindow* _Nonnull GetNSWindow () = 0;
virtual NSView* _Nonnull GetNSView () = 0; virtual AvnView* _Nonnull GetNSView () = 0;
}; };
#endif //AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H #endif //AVALONIA_NATIVE_OSX_INSWINDOWHOLDER_H

6
native/Avalonia.Native/src/OSX/WindowBaseImpl.h

@ -26,7 +26,7 @@ BEGIN_INTERFACE_MAP()
virtual ~WindowBaseImpl(); virtual ~WindowBaseImpl();
WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl); WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl, bool usePanel = false);
virtual HRESULT ObtainNSWindowHandle(void **ret) override; virtual HRESULT ObtainNSWindowHandle(void **ret) override;
@ -38,7 +38,7 @@ BEGIN_INTERFACE_MAP()
virtual NSWindow *GetNSWindow() override; virtual NSWindow *GetNSWindow() override;
virtual NSView *GetNSView() override; virtual AvnView *GetNSView() override;
virtual HRESULT Show(bool activate, bool isDialog) override; virtual HRESULT Show(bool activate, bool isDialog) override;
@ -99,6 +99,8 @@ BEGIN_INTERFACE_MAP()
virtual bool IsDialog(); virtual bool IsDialog();
id<AvnWindowProtocol> GetWindowProtocol (); id<AvnWindowProtocol> GetWindowProtocol ();
virtual void BringToFront ();
protected: protected:
virtual NSWindowStyleMask GetStyle(); virtual NSWindowStyleMask GetStyle();

19
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@ -21,7 +21,7 @@ WindowBaseImpl::~WindowBaseImpl() {
Window = nullptr; Window = nullptr;
} }
WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl) { WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl, bool usePanel) {
_shown = false; _shown = false;
_inResize = false; _inResize = false;
BaseEvents = events; BaseEvents = events;
@ -36,8 +36,10 @@ WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl)
lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX}; lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX};
lastMinSize = NSSize { 0, 0 }; lastMinSize = NSSize { 0, 0 };
Window = nullptr;
lastMenu = nullptr; lastMenu = nullptr;
CreateNSWindow(usePanel);
InitialiseNSWindow();
} }
HRESULT WindowBaseImpl::ObtainNSViewHandle(void **ret) { HRESULT WindowBaseImpl::ObtainNSViewHandle(void **ret) {
@ -68,7 +70,7 @@ NSWindow *WindowBaseImpl::GetNSWindow() {
return Window; return Window;
} }
NSView *WindowBaseImpl::GetNSView() { AvnView *WindowBaseImpl::GetNSView() {
return View; return View;
} }
@ -88,7 +90,6 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
START_COM_CALL; START_COM_CALL;
@autoreleasepool { @autoreleasepool {
CreateNSWindow(isDialog);
InitialiseNSWindow(); InitialiseNSWindow();
if(hasPosition) if(hasPosition)
@ -143,8 +144,6 @@ HRESULT WindowBaseImpl::Hide() {
@autoreleasepool { @autoreleasepool {
if (Window != nullptr) { if (Window != nullptr) {
[Window orderOut:Window]; [Window orderOut:Window];
[GetWindowProtocol() restoreParentWindow];
} }
return S_OK; return S_OK;
@ -558,6 +557,8 @@ void WindowBaseImpl::CreateNSWindow(bool isDialog) {
CleanNSWindow(); CleanNSWindow();
Window = [[AvnPanel alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:GetStyle()]; Window = [[AvnPanel alloc] initWithParent:this contentRect:NSRect{0, 0, lastSize} styleMask:GetStyle()];
[Window setHidesOnDeactivate:false];
} }
} else { } else {
if (![Window isKindOfClass:[AvnWindow class]]) { if (![Window isKindOfClass:[AvnWindow class]]) {
@ -585,6 +586,7 @@ void WindowBaseImpl::InitialiseNSWindow() {
[Window setOpaque:false]; [Window setOpaque:false];
[Window setHasShadow:true];
[Window invalidateShadow]; [Window invalidateShadow];
if (lastMenu != nullptr) { if (lastMenu != nullptr) {
@ -608,6 +610,11 @@ id <AvnWindowProtocol> WindowBaseImpl::GetWindowProtocol() {
return (id <AvnWindowProtocol>) Window; return (id <AvnWindowProtocol>) Window;
} }
void WindowBaseImpl::BringToFront()
{
// do nothing.
}
extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events, IAvnGlContext* gl) extern IAvnWindow* CreateAvnWindow(IAvnWindowEvents*events, IAvnGlContext* gl)
{ {
@autoreleasepool @autoreleasepool

7
native/Avalonia.Native/src/OSX/WindowImpl.h

@ -8,6 +8,7 @@
#import "WindowBaseImpl.h" #import "WindowBaseImpl.h"
#include "IWindowStateChanged.h" #include "IWindowStateChanged.h"
#include <list>
class WindowImpl : public virtual WindowBaseImpl, public virtual IAvnWindow, public IWindowStateChanged class WindowImpl : public virtual WindowBaseImpl, public virtual IAvnWindow, public IWindowStateChanged
{ {
@ -22,6 +23,8 @@ private:
bool _transitioningWindowState; bool _transitioningWindowState;
bool _isClientAreaExtended; bool _isClientAreaExtended;
bool _isDialog; bool _isDialog;
WindowImpl* _parent;
std::list<WindowImpl*> _children;
AvnExtendClientAreaChromeHints _extendClientHints; AvnExtendClientAreaChromeHints _extendClientHints;
FORWARD_IUNKNOWN() FORWARD_IUNKNOWN()
@ -90,6 +93,10 @@ BEGIN_INTERFACE_MAP()
virtual bool IsDialog() override; virtual bool IsDialog() override;
virtual void OnInitialiseNSWindow() override; virtual void OnInitialiseNSWindow() override;
virtual void BringToFront () override;
bool CanBecomeKeyWindow ();
protected: protected:
virtual NSWindowStyleMask GetStyle() override; virtual NSWindowStyleMask GetStyle() override;

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

@ -10,6 +10,7 @@
#include "WindowProtocol.h" #include "WindowProtocol.h"
WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBaseImpl(events, gl) { WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBaseImpl(events, gl) {
_children = std::list<WindowImpl*>();
_isClientAreaExtended = false; _isClientAreaExtended = false;
_extendClientHints = AvnDefaultChrome; _extendClientHints = AvnDefaultChrome;
_fullScreenActive = false; _fullScreenActive = false;
@ -20,6 +21,7 @@ WindowImpl::WindowImpl(IAvnWindowEvents *events, IAvnGlContext *gl) : WindowBase
_lastWindowState = Normal; _lastWindowState = Normal;
_actualWindowState = Normal; _actualWindowState = Normal;
_lastTitle = @""; _lastTitle = @"";
_parent = nullptr;
WindowEvents = events; WindowEvents = events;
} }
@ -28,24 +30,12 @@ void WindowImpl::HideOrShowTrafficLights() {
return; return;
} }
for (id subview in Window.contentView.superview.subviews) { bool wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) { bool hasTrafficLights = _isClientAreaExtended ? !wantsChrome : _decorations != SystemDecorationsFull;
NSView *titlebarView = [subview subviews][0];
for (id button in titlebarView.subviews) { [[Window standardWindowButton:NSWindowCloseButton] setHidden:hasTrafficLights];
if ([button isKindOfClass:[NSButton class]]) { [[Window standardWindowButton:NSWindowMiniaturizeButton] setHidden:hasTrafficLights];
if (_isClientAreaExtended) { [[Window standardWindowButton:NSWindowZoomButton] setHidden:hasTrafficLights];
auto wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
[button setHidden:!wantsChrome];
} else {
[button setHidden:(_decorations != SystemDecorationsFull)];
}
[button setWantsLayer:true];
}
}
}
}
} }
void WindowImpl::OnInitialiseNSWindow(){ void WindowImpl::OnInitialiseNSWindow(){
@ -61,6 +51,11 @@ void WindowImpl::OnInitialiseNSWindow(){
[GetWindowProtocol() setIsExtended:true]; [GetWindowProtocol() setIsExtended:true];
SetExtendClientArea(true); SetExtendClientArea(true);
} }
if(_parent != nullptr)
{
SetParent(_parent);
}
} }
HRESULT WindowImpl::Show(bool activate, bool isDialog) { HRESULT WindowImpl::Show(bool activate, bool isDialog) {
@ -90,26 +85,68 @@ HRESULT WindowImpl::SetParent(IAvnWindow *parent) {
START_COM_CALL; START_COM_CALL;
@autoreleasepool { @autoreleasepool {
if (parent == nullptr) if(_parent != nullptr)
return E_POINTER; {
_parent->_children.remove(this);
auto parent = _parent;
dispatch_async(dispatch_get_main_queue(), ^{
parent->BringToFront();
});
}
auto cparent = dynamic_cast<WindowImpl *>(parent); auto cparent = dynamic_cast<WindowImpl *>(parent);
if (cparent == nullptr)
return E_INVALIDARG; _parent = cparent;
// If one tries to show a child window with a minimized parent window, then the parent window will be if(_parent != nullptr && Window != nullptr){
// restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive // If one tries to show a child window with a minimized parent window, then the parent window will be
// state. Detect this and explicitly restore the parent window ourselves to avoid this situation. // restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive
if (cparent->WindowState() == Minimized) // state. Detect this and explicitly restore the parent window ourselves to avoid this situation.
cparent->SetWindowState(Normal); if (cparent->WindowState() == Minimized)
cparent->SetWindowState(Normal);
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
cparent->_children.push_back(this);
UpdateStyle();
}
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; return S_OK;
[cparent->Window addChildWindow:Window ordered:NSWindowAbove]; }
}
UpdateStyle(); void WindowImpl::BringToFront()
{
if(IsDialog())
{
Activate();
}
else
{
[Window orderFront:nullptr];
}
[Window invalidateShadow];
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++)
{
(*iterator)->BringToFront();
}
}
return S_OK; bool WindowImpl::CanBecomeKeyWindow()
{
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++)
{
if((*iterator)->IsDialog())
{
return false;
}
} }
return true;
} }
void WindowImpl::StartStateTransition() { void WindowImpl::StartStateTransition() {
@ -523,7 +560,7 @@ bool WindowImpl::IsDialog() {
} }
NSWindowStyleMask WindowImpl::GetStyle() { NSWindowStyleMask WindowImpl::GetStyle() {
unsigned long s = this->_isDialog ? NSWindowStyleMaskDocModalWindow : NSWindowStyleMaskBorderless; unsigned long s = NSWindowStyleMaskBorderless;
switch (_decorations) { switch (_decorations) {
case SystemDecorationsNone: case SystemDecorationsNone:
@ -535,7 +572,7 @@ NSWindowStyleMask WindowImpl::GetStyle() {
break; break;
case SystemDecorationsFull: case SystemDecorationsFull:
s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskBorderless; s = s | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable;
if (_canResize) { if (_canResize) {
s = s | NSWindowStyleMaskResizable; s = s | NSWindowStyleMaskResizable;
@ -543,7 +580,7 @@ NSWindowStyleMask WindowImpl::GetStyle() {
break; break;
} }
if ([Window parentWindow] == nullptr) { if (!IsDialog()) {
s |= NSWindowStyleMaskMiniaturizable; s |= NSWindowStyleMaskMiniaturizable;
} }

1
native/Avalonia.Native/src/OSX/WindowProtocol.h

@ -11,7 +11,6 @@
@protocol AvnWindowProtocol @protocol AvnWindowProtocol
-(void) pollModalSession: (NSModalSession _Nonnull) session; -(void) pollModalSession: (NSModalSession _Nonnull) session;
-(void) restoreParentWindow;
-(bool) shouldTryToHandleEvents; -(bool) shouldTryToHandleEvents;
-(void) setEnabled: (bool) enable; -(void) setEnabled: (bool) enable;
-(void) showAppMenuOnly; -(void) showAppMenuOnly;

2
samples/ControlCatalog/Pages/DialogsPage.xaml

@ -20,7 +20,7 @@
Text="Window dialogs" /> Text="Window dialogs" />
<Button Name="DecoratedWindow">Decorated _window</Button> <Button Name="DecoratedWindow">Decorated _window</Button>
<Button Name="DecoratedWindowDialog">Decorated w_indow (dialog)</Button> <Button Name="DecoratedWindowDialog">Decorated w_indow (dialog)</Button>
<Button Name="Dialog">_Dialog</Button> <Button Name="Dialog" ToolTip.Tip="Shows a dialog">_Dialog</Button>
<Button Name="DialogNoTaskbar">Dialog (_No taskbar icon)</Button> <Button Name="DialogNoTaskbar">Dialog (_No taskbar icon)</Button>
<Button Name="OwnedWindow">Own_ed window</Button> <Button Name="OwnedWindow">Own_ed window</Button>
<Button Name="OwnedWindowNoTaskbar">Owned window (No tas_kbar icon)</Button> <Button Name="OwnedWindowNoTaskbar">Owned window (No tas_kbar icon)</Button>

13
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@ -151,6 +151,7 @@ namespace ControlCatalog.Pages
private Window CreateSampleWindow() private Window CreateSampleWindow()
{ {
Button button; Button button;
Button dialogButton;
var window = new Window var window = new Window
{ {
@ -167,6 +168,12 @@ namespace ControlCatalog.Pages
HorizontalAlignment = HorizontalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center,
Content = "Click to close", Content = "Click to close",
IsDefault = true IsDefault = true
}),
(dialogButton = new Button
{
HorizontalAlignment = HorizontalAlignment.Center,
Content = "Dialog",
IsDefault = false
}) })
} }
}, },
@ -174,6 +181,12 @@ namespace ControlCatalog.Pages
}; };
button.Click += (_, __) => window.Close(); button.Click += (_, __) => window.Close();
dialogButton.Click += (_, __) =>
{
var dialog = CreateSampleWindow();
dialog.Height = 200;
dialog.ShowDialog(window);
};
return window; return window;
} }

9
src/Avalonia.Base/Data/Converters/DefaultValueConverter.cs

@ -33,7 +33,14 @@ namespace Avalonia.Data.Converters
if (typeof(ICommand).IsAssignableFrom(targetType) && value is Delegate d && d.Method.GetParameters().Length <= 1) if (typeof(ICommand).IsAssignableFrom(targetType) && value is Delegate d && d.Method.GetParameters().Length <= 1)
{ {
return new MethodToCommandConverter(d); if (d.Method.IsPrivate == false)
{
return new MethodToCommandConverter(d);
}
else
{
return new BindingNotification(new InvalidCastException("You can't bind to private methods!"), BindingErrorType.Error);
}
} }
if (TypeUtilities.TryConvert(targetType, value, culture, out var result)) if (TypeUtilities.TryConvert(targetType, value, culture, out var result))

5
src/Avalonia.Controls/ContextMenu.cs

@ -450,6 +450,11 @@ namespace Avalonia.Controls
if (sender is Control control if (sender is Control control
&& control.ContextMenu is ContextMenu contextMenu) && control.ContextMenu is ContextMenu contextMenu)
{ {
if (contextMenu._popup?.Parent == control)
{
((ISetLogicalParent)contextMenu._popup).SetParent(null);
}
contextMenu.Close(); contextMenu.Close();
} }
} }

3
src/Avalonia.Controls/Flyouts/FlyoutBase.cs

@ -175,7 +175,8 @@ namespace Avalonia.Controls.Primitives
IsOpen = false; IsOpen = false;
Popup.IsOpen = false; Popup.IsOpen = false;
((ISetLogicalParent)Popup).SetParent(null);
// Ensure this isn't active // Ensure this isn't active
_transientDisposable?.Dispose(); _transientDisposable?.Dispose();
_transientDisposable = null; _transientDisposable = null;

21
tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs

@ -446,6 +446,27 @@ namespace Avalonia.Controls.UnitTests
} }
} }
[Fact]
public void Should_Reset_Popup_Parent_On_Target_Detached()
{
using (Application())
{
var userControl = new UserControl();
var window = PreparedWindow(userControl);
window.Show();
var menu = new ContextMenu();
userControl.ContextMenu = menu;
menu.Open();
var popup = Assert.IsType<Popup>(menu.Parent);
Assert.NotNull(popup.Parent);
window.Content = null;
Assert.Null(popup.Parent);
}
}
[Fact] [Fact]
public void Context_Menu_In_Resources_Can_Be_Shared() public void Context_Menu_In_Resources_Can_Be_Shared()
{ {

25
tests/Avalonia.Controls.UnitTests/FlyoutTests.cs

@ -432,6 +432,26 @@ namespace Avalonia.Controls.UnitTests
} }
} }
[Fact]
public void Should_Reset_Popup_Parent_On_Target_Detached()
{
using (CreateServicesWithFocus())
{
var userControl = new UserControl();
var window = PreparedWindow(userControl);
window.Show();
var flyout = new TestFlyout();
flyout.ShowAt(userControl);
var popup = Assert.IsType<Popup>(flyout.Popup);
Assert.NotNull(popup.Parent);
window.Content = null;
Assert.Null(popup.Parent);
}
}
[Fact] [Fact]
public void ContextFlyout_Can_Be_Set_In_Styles() public void ContextFlyout_Can_Be_Set_In_Styles()
{ {
@ -549,5 +569,10 @@ namespace Avalonia.Controls.UnitTests
new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed), new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed),
KeyModifiers.None); KeyModifiers.None);
} }
public class TestFlyout : Flyout
{
public new Popup Popup => base.Popup;
}
} }
} }

32
tests/Avalonia.Markup.UnitTests/Data/BindingTests_Method.cs

@ -0,0 +1,32 @@
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Xunit;
namespace Avalonia.Markup.UnitTests.Data
{
public class BindingTests_Method
{
[Fact]
public void Binding_To_Private_Methods_Shouldnt_Work()
{
var vm = new TestClass();
var target = new Button
{
DataContext = vm,
[!Button.CommandProperty] = new Binding("MyMethod"),
};
target.RaiseEvent(new RoutedEventArgs(AccessKeyHandler.AccessKeyPressedEvent));
Assert.False(vm.IsSet);
}
class TestClass
{
public bool IsSet { get; set; }
private void MyMethod() => IsSet = true;
}
}
}
Loading…
Cancel
Save