Browse Source

only create the NSWindow when show is called. Cache sizes until needed.

pull/8091/head
Dan Walmsley 4 years ago
parent
commit
4cba4519f3
  1. 11
      native/Avalonia.Native/src/OSX/WindowBaseImpl.h
  2. 53
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
  3. 2
      native/Avalonia.Native/src/OSX/window.h
  4. 6
      native/Avalonia.Native/src/OSX/window.mm

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

@ -24,10 +24,7 @@ BEGIN_INTERFACE_MAP()
INTERFACE_MAP_ENTRY(IAvnWindowBase, IID_IAvnWindowBase)
END_INTERFACE_MAP()
virtual ~WindowBaseImpl() {
View = NULL;
Window = NULL;
}
virtual ~WindowBaseImpl();
AutoFitContentView *StandardContainer;
AvnView *View;
@ -36,6 +33,9 @@ BEGIN_INTERFACE_MAP()
ComPtr<IAvnGlContext> _glContext;
NSObject <IRenderTarget> *renderTarget;
AvnPoint lastPositionSet;
NSSize lastSize;
NSSize lastMinSize;
NSSize lastMaxSize;
NSString *_lastTitle;
bool _shown;
@ -116,6 +116,9 @@ protected:
void UpdateStyle();
private:
void InitialiseNSWindow ();
};
#endif //AVALONIA_NATIVE_OSX_WINDOWBASEIMPL_H

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

@ -12,6 +12,13 @@
#import "cursor.h"
#include "ResizeScope.h"
#import "AutoFitContentView.h"
#include "WindowBaseImpl.h"
WindowBaseImpl::~WindowBaseImpl() {
View = nullptr;
Window = nullptr;
}
WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, IAvnGlContext *gl) {
_shown = false;
@ -22,17 +29,11 @@ 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 = @"";
[Window setStyleMask:NSWindowStyleMaskBorderless];
[Window setBackingType:NSBackingStoreBuffered];
[Window setOpaque:false];
Window = nullptr;
}
HRESULT WindowBaseImpl::ObtainNSViewHandle(void **ret) {
@ -83,6 +84,8 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
START_COM_CALL;
@autoreleasepool {
InitialiseNSWindow();
SetPosition(lastPositionSet);
UpdateStyle();
@ -97,6 +100,10 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
[Window orderFront:Window];
}
[Window setContentMinSize:lastMinSize];
[Window setContentMaxSize:lastMaxSize];
[Window setContentSize: lastSize];
_shown = true;
return S_OK;
@ -225,8 +232,13 @@ HRESULT WindowBaseImpl::SetMinMaxSize(AvnSize minSize, AvnSize maxSize) {
START_COM_CALL;
@autoreleasepool {
[Window setMinSize:ToNSSize(minSize)];
[Window setMaxSize:ToNSSize(maxSize)];
lastMinSize = ToNSSize(minSize);
lastMaxSize = ToNSSize(maxSize);
if(Window != nullptr) {
[Window setContentMinSize:lastMinSize];
[Window setContentMaxSize:lastMaxSize];
}
return S_OK;
}
@ -243,8 +255,8 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
auto resizeBlock = ResizeScope(View, reason);
@autoreleasepool {
auto maxSize = [Window maxSize];
auto minSize = [Window minSize];
auto maxSize = lastMaxSize;
auto minSize = lastMinSize;
if (x < minSize.width) {
x = minSize.width;
@ -267,8 +279,12 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
BaseEvents->Resized(AvnSize{x, y}, reason);
}
[Window setContentSize:NSSize{x, y}];
[Window invalidateShadow];
lastSize = NSSize {x, y};
if(Window != nullptr) {
[Window setContentSize:lastSize];
[Window invalidateShadow];
}
}
@finally {
_inResize = false;
@ -502,4 +518,13 @@ NSWindowStyleMask WindowBaseImpl::GetStyle() {
void WindowBaseImpl::UpdateStyle() {
[Window setStyleMask:GetStyle()];
}
}
void WindowBaseImpl::InitialiseNSWindow() {
Window = [[AvnWindow alloc] initWithParent:this contentRect:NSRect{ 0, 0, lastSize } styleMask:GetStyle()];
[Window setContentView:StandardContainer];
[Window setStyleMask:NSWindowStyleMaskBorderless];
[Window setBackingType:NSBackingStoreBuffered];
[Window setOpaque:false];
}

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

@ -8,7 +8,7 @@
class WindowBaseImpl;
@interface AvnWindow : NSWindow <NSWindowDelegate>
-(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
-(AvnWindow* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask;
-(void) setCanBecomeKeyAndMain;
-(void) pollModalSession: (NSModalSession _Nonnull) session;
-(void) restoreParentWindow;

6
native/Avalonia.Native/src/OSX/window.mm

@ -143,9 +143,10 @@
_canBecomeKeyAndMain = true;
}
-(AvnWindow*) initWithParent: (WindowBaseImpl*) parent
-(AvnWindow*) initWithParent: (WindowBaseImpl*) parent contentRect: (NSRect)contentRect styleMask: (NSWindowStyleMask)styleMask;
{
self = [super init];
self = [super initWithContentRect:contentRect styleMask: styleMask backing:NSBackingStoreBuffered defer:false];
[self setReleasedWhenClosed:false];
_parent = parent;
[self setDelegate:self];
@ -155,6 +156,7 @@
[self backingScaleFactor];
[self setOpaque:NO];
[self setBackgroundColor: [NSColor clearColor]];
_isExtended = false;
return self;
}

Loading…
Cancel
Save