Skip to content

Commit

Permalink
Merge branch 'master' into themeresource
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 authored May 24, 2022
2 parents cc446d2 + 115d62e commit 174b10d
Show file tree
Hide file tree
Showing 32 changed files with 1,237 additions and 468 deletions.
34 changes: 22 additions & 12 deletions native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @implementation CLASS_NAME
ComPtr<WindowBaseImpl> _parent;
bool _closed;
bool _isEnabled;
bool _canBecomeKeyWindow;
bool _isExtended;
AvnMenu* _menu;
}
Expand Down Expand Up @@ -216,29 +217,38 @@ - (void)windowWillClose:(NSNotification *)notification

-(BOOL)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])
if(_canBecomeKeyWindow)
{
if (![uch conformsToProtocol:@protocol(AvnWindowProtocol)])
// 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])
{
continue;
}
if (![uch conformsToProtocol:@protocol(AvnWindowProtocol)])
{
continue;
}

id <AvnWindowProtocol> ch = (id <AvnWindowProtocol>) uch;
id <AvnWindowProtocol> ch = (id <AvnWindowProtocol>) uch;

return !ch.isDialog;
}
if(ch.isDialog)
return false;
}

return true;
return true;
}

return false;
}

#ifndef IS_NSPANEL
-(BOOL)canBecomeMainWindow
{
#ifdef IS_NSPANEL
return false;
#else
return true;
}
#endif

-(void)setCanBecomeKeyWindow:(bool)value
{
_canBecomeKeyWindow = value;
}

-(bool)shouldTryToHandleEvents
Expand Down
8 changes: 6 additions & 2 deletions native/Avalonia.Native/src/OSX/PopupImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
PopupImpl(IAvnWindowEvents* events, IAvnGlContext* gl) : WindowBaseImpl(events, gl)
{
WindowEvents = events;
[Window setLevel:NSPopUpMenuWindowLevel];
}
protected:
virtual NSWindowStyleMask GetStyle() override
{
return NSWindowStyleMaskBorderless;
}

virtual void OnInitialiseNSWindow () override
{
[Window setLevel:NSPopUpMenuWindowLevel];
}

public:
virtual bool ShouldTakeFocusOnShow() override
Expand All @@ -54,4 +58,4 @@ virtual HRESULT Show(bool activate, bool isDialog) override
IAvnPopup* ptr = dynamic_cast<IAvnPopup*>(new PopupImpl(events, gl));
return ptr;
}
}
}
41 changes: 22 additions & 19 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
class WindowBaseImpl : public virtual ComObject,
public virtual IAvnWindowBase,
public INSWindowHolder {
private:
NSCursor *cursor;

public:
FORWARD_IUNKNOWN()
Expand All @@ -28,23 +26,6 @@ BEGIN_INTERFACE_MAP()

virtual ~WindowBaseImpl();

AutoFitContentView *StandardContainer;
AvnView *View;
NSWindow * Window;
ComPtr<IAvnWindowBaseEvents> BaseEvents;
ComPtr<IAvnGlContext> _glContext;
NSObject <IRenderTarget> *renderTarget;
AvnPoint lastPositionSet;
bool hasPosition;
NSSize lastSize;
NSSize lastMinSize;
NSSize lastMaxSize;
AvnMenu* lastMenu;
NSString *_lastTitle;

bool _shown;
bool _inResize;

WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl);

virtual HRESULT ObtainNSWindowHandle(void **ret) override;
Expand Down Expand Up @@ -123,11 +104,33 @@ BEGIN_INTERFACE_MAP()
virtual NSWindowStyleMask GetStyle();

void UpdateStyle();

virtual void OnInitialiseNSWindow ();

private:
void CreateNSWindow (bool isDialog);
void CleanNSWindow ();
void InitialiseNSWindow ();

NSCursor *cursor;
ComPtr<IAvnGlContext> _glContext;
bool hasPosition;
NSSize lastSize;
NSSize lastMinSize;
NSSize lastMaxSize;
AvnMenu* lastMenu;
bool _inResize;

protected:
AvnPoint lastPositionSet;
AutoFitContentView *StandardContainer;
bool _shown;

public:
NSObject <IRenderTarget> *renderTarget;
NSWindow * Window;
ComPtr<IAvnWindowBaseEvents> BaseEvents;
AvnView *View;
};

#endif //AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H
10 changes: 7 additions & 3 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
lastSize = NSSize { 100, 100 };
lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX};
lastMinSize = NSSize { 0, 0 };
_lastTitle = @"";

Window = nullptr;
lastMenu = nullptr;
Expand Down Expand Up @@ -102,8 +101,6 @@

UpdateStyle();

[Window setTitle:_lastTitle];

if (ShouldTakeFocusOnShow() && activate) {
[Window orderFront:Window];
[Window makeKeyAndOrderFront:Window];
Expand Down Expand Up @@ -570,6 +567,11 @@
}
}

void WindowBaseImpl::OnInitialiseNSWindow()
{

}

void WindowBaseImpl::InitialiseNSWindow() {
if(Window != nullptr) {
[Window setContentView:StandardContainer];
Expand All @@ -589,6 +591,8 @@
[GetWindowProtocol() showWindowMenuWithAppMenu];
}
}

OnInitialiseNSWindow();
}
}

Expand Down
5 changes: 5 additions & 0 deletions native/Avalonia.Native/src/OSX/WindowImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,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
30 changes: 16 additions & 14 deletions native/Avalonia.Native/src/OSX/WindowImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
_inSetWindowState = false;
_lastWindowState = Normal;
_actualWindowState = Normal;
_lastTitle = @"";
WindowEvents = events;
[Window disableCursorRects];
[Window setTabbingMode:NSWindowTabbingModeDisallowed];
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
}

void WindowImpl::HideOrShowTrafficLights() {
Expand Down Expand Up @@ -50,25 +48,29 @@
}
}

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;

bool created = Window == nullptr;

WindowBaseImpl::Show(activate, isDialog);

if(created)
{
if(_isClientAreaExtended)
{
[GetWindowProtocol() setIsExtended:true];
SetExtendClientArea(true);
}
}

HideOrShowTrafficLights();

return SetWindowState(_lastWindowState);
Expand Down
4 changes: 3 additions & 1 deletion native/Avalonia.Native/src/OSX/WindowProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
-(void) setIsExtended:(bool)value;
-(void) disconnectParent;
-(bool) isDialog;
@end

-(void) setCanBecomeKeyWindow:(bool)value;
@end
46 changes: 23 additions & 23 deletions src/Avalonia.Base/Data/Core/ExpressionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,36 @@ protected virtual void NextValueChanged(object? value)

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<object?>(value) : NullReference;
var notification = value as BindingNotification;
var next = Next;

if (Next != null)
if (notification == null)
{
Next.Target = LastValue;
LastValue = value != null ? new WeakReference<object?>(value) : NullReference;
if (next != null)
{
next.Target = LastValue;
}
else if (notify)
{
subscriber(value);
}
}
else if (notify)
else
{
_subscriber(value);
}
}
else
{
LastValue = notification.Value != null ? new WeakReference<object?>(notification.Value) : NullReference;
LastValue = notification.Value != null ? new WeakReference<object?>(notification.Value) : NullReference;

if (Next != null)
{
Next.Target = LastValue;
}
if (next != null)
{
next.Target = LastValue;
}

if (Next == null || notification.Error != null)
{
_subscriber(value);
if (next == null || notification.Error != null)
{
subscriber(value);
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Avalonia.Base/Styling/ChildSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public override string ToString()
return _selectorString;
}

protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
protected override SelectorMatch Evaluate(IStyleable control, IStyle? parent, bool subscribe)
{
var controlParent = ((ILogical)control).LogicalParent;

if (controlParent != null)
{
var parentMatch = _parent.Match((IStyleable)controlParent, subscribe);
var parentMatch = _parent.Match((IStyleable)controlParent, parent, subscribe);

if (parentMatch.Result == SelectorMatchResult.Sometimes)
{
Expand All @@ -65,5 +65,6 @@ protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
}

protected override Selector? MovePrevious() => null;
internal override bool HasValidNestingSelector() => _parent.HasValidNestingSelector();
}
}
5 changes: 3 additions & 2 deletions src/Avalonia.Base/Styling/DescendentSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override string ToString()
return _selectorString;
}

protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
protected override SelectorMatch Evaluate(IStyleable control, IStyle? parent, bool subscribe)
{
var c = (ILogical)control;
var descendantMatches = new OrActivatorBuilder();
Expand All @@ -46,7 +46,7 @@ protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)

if (c is IStyleable)
{
var match = _parent.Match((IStyleable)c, subscribe);
var match = _parent.Match((IStyleable)c, parent, subscribe);

if (match.Result == SelectorMatchResult.Sometimes)
{
Expand All @@ -70,5 +70,6 @@ protected override SelectorMatch Evaluate(IStyleable control, bool subscribe)
}

protected override Selector? MovePrevious() => null;
internal override bool HasValidNestingSelector() => _parent.HasValidNestingSelector();
}
}
Loading

0 comments on commit 174b10d

Please sign in to comment.