Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/osx popup flyout fixes #8180

Merged
merged 6 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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