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

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

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

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

@ -143,9 +143,10 @@
_canBecomeKeyAndMain = true; _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]; [self setReleasedWhenClosed:false];
_parent = parent; _parent = parent;
[self setDelegate:self]; [self setDelegate:self];
@ -155,6 +156,7 @@
[self backingScaleFactor]; [self backingScaleFactor];
[self setOpaque:NO]; [self setOpaque:NO];
[self setBackgroundColor: [NSColor clearColor]]; [self setBackgroundColor: [NSColor clearColor]];
_isExtended = false; _isExtended = false;
return self; return self;
} }

Loading…
Cancel
Save