NSWindowTemplate: Add a lot more properties

These are required by Xcode. TODO: actually use them.
This commit is contained in:
Ariel Abreu 2023-10-13 10:22:23 -04:00
parent bd843143fb
commit 491b0b0418
No known key found for this signature in database
GPG Key ID: 5B88AAAF4280706F
2 changed files with 335 additions and 14 deletions

View File

@ -19,26 +19,103 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSGeometry.h>
#import <Foundation/NSObject.h>
#import <AppKit/NSUserInterfaceItemIdentification.h>
#import <AppKit/NSWindow.h>
@class NSView;
@interface NSWindowTemplate : NSObject {
typedef NS_OPTIONS(uint32_t, NSWindowTemplateFlags) {
NSWindowTemplateFlagRestorable = 1u << 9,
NSWindowTemplateFlagDoesNotShowToolbarButton = 1u << 10,
NSWindowTemplateFlagAutorecalculatesKeyViewLoop = 1u << 11,
NSWindowTemplateFlagNoShadow = 1u << 12,
NSWindowTemplateFlagAllowsToolTipsWhenApplicationIsInactive = 1u << 13,
NSWindowTemplateFlagAutoPositionShift = 19,
NSWindowTemplateFlagAutoPositionMask = 0x3fu << NSWindowTemplateFlagAutoPositionShift,
NSWindowTemplateFlagHasDynamicDepthLimit = 1u << 25,
NSWindowTemplateFlagWantsToBeColor = 1u << 26,
NSWindowTemplateFlagOneShot = 1u << 28,
NSWindowTemplateFlagDeferred = 1u << 29,
NSWindowTemplateFlagNotReleasedWhenClosed = 1u << 30,
NSWindowTemplateFlagHidesOnDeactivate = 1u << 31,
};
@interface NSWindowTemplate : NSObject <NSUserInterfaceItemIdentification> {
// the ivars without a `_` prefix are like that because Xcode
// requires them to be named like that.
// TODO: we might also need to put these ivars in the same order as the real AppKit does.
// this is only a problem for platforms with fragile base classes (e.g. i386), though.
NSSize _maxSize;
NSSize _minSize;
NSSize _contentMinSize;
NSSize _contentMaxSize;
NSRect screenRect;
id _viewClass;
unsigned _wtFlags;
int _windowBacking;
NSWindowTemplateFlags _wtFlags;
NSInteger _windowBacking;
NSString *_windowClass;
NSRect windowRect;
int _windowStyleMask;
NSWindowStyleMask _windowStyleMask;
NSString *_windowTitle;
NSView *windowView;
NSString *_windowAutosave;
NSUserInterfaceItemIdentifier _identifier;
NSWindowCollectionBehavior _collectionBehavior;
NSUInteger _animationBehavior;
NSSize _minFullScreenContentSize;
NSSize _maxFullScreenContentSize;
NSString *_tabbingIdentifier;
NSUInteger _tabbingMode;
NSUInteger _titleVisibility;
NSToolbar *_toolbar;
CGFloat _contentBorderThicknessForMinXEdge;
CGFloat _contentBorderThicknessForMaxXEdge;
CGFloat _contentBorderThicknessForMinYEdge;
CGFloat _contentBorderThicknessForMaxYEdge;
BOOL _titlebarAppearsTransparent;
BOOL _autorecalculatesContentBorderThicknessForMinXEdge;
BOOL _autorecalculatesContentBorderThicknessForMaxXEdge;
BOOL _autorecalculatesContentBorderThicknessForMinYEdge;
BOOL _autorecalculatesContentBorderThicknessForMaxYEdge;
}
@property NSWindowStyleMask styleMask;
@property(copy) NSString *title;
@property BOOL allowsToolTipsWhenApplicationIsInactive;
@property BOOL autorecalculatesKeyViewLoop;
@property(getter=isDeferred) BOOL deferred;
@property BOOL hasShadow;
@property BOOL hidesOnDeactivate;
@property(getter=isReleasedWhenClosed) BOOL releasedWhenClosed;
@property(getter=isOneShot) BOOL oneShot;
@property NSWindowCollectionBehavior collectionBehavior;
@property NSUInteger animationBehavior;
@property(copy) NSString *frameAutosaveName;
@property NSSize contentMinSize;
@property NSSize contentMaxSize;
@property NSSize minFullScreenContentSize;
@property NSSize maxFullScreenContentSize;
@property(copy) NSString *tabbingIdentifier;
@property NSUInteger tabbingMode;
@property BOOL titlebarAppearsTransparent;
@property NSUInteger titleVisibility;
@property(strong) NSToolbar *toolbar;
@property(getter=isRestorable) BOOL restorable;
@property uint32_t autoPositionMask;
@property BOOL wantsToBeColor;
@property NSSize minSize;
@property NSSize maxSize;
@property(copy) NSString *className;
- (BOOL) autorecalculatesContentBorderThicknessForEdge: (NSRectEdge) edge;
- (void) setAutorecalculatesContentBorderThickness: (BOOL) autorecalculatesContentBorderThickness
forEdge: (NSRectEdge) edge;
- (CGFloat) contentBorderThicknessForEdge: (NSRectEdge) edge;
- (void) setContentBorderThickness: (CGFloat) contentBorderThickness
forEdge: (NSRectEdge) edge;
@end

View File

@ -22,6 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <AppKit/NSScreen.h>
#import <AppKit/NSWindow-Private.h>
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSRaise.h>
@interface NSWindow (private)
+ (BOOL) hasMainMenuForStyleMask: (NSUInteger) styleMask;
@ -30,6 +31,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
@implementation NSWindowTemplate
@synthesize identifier = _identifier;
@synthesize styleMask = _windowStyleMask;
@synthesize title = _windowTitle;
@synthesize collectionBehavior = _collectionBehavior;
@synthesize animationBehavior = _animationBehavior;
@synthesize frameAutosaveName = _windowAutosave;
@synthesize contentMinSize = _contentMinSize;
@synthesize contentMaxSize = _contentMaxSize;
@synthesize minFullScreenContentSize = _minFullScreenContentSize;
@synthesize maxFullScreenContentSize = _maxFullScreenContentSize;
@synthesize tabbingIdentifier = _tabbingIdentifier;
@synthesize tabbingMode = _tabbingMode;
@synthesize titlebarAppearsTransparent = _titlebarAppearsTransparent;
@synthesize titleVisibility = _titleVisibility;
@synthesize toolbar = _toolbar;
@synthesize minSize = _minSize;
@synthesize maxSize = _maxSize;
@synthesize className = _windowClass;
- (instancetype) init {
self = [super init];
if (self != nil) {
_autorecalculatesContentBorderThicknessForMinXEdge = YES;
_autorecalculatesContentBorderThicknessForMaxXEdge = YES;
_autorecalculatesContentBorderThicknessForMinYEdge = YES;
_autorecalculatesContentBorderThicknessForMaxYEdge = YES;
}
return self;
}
- (instancetype) initWithCoder: (NSCoder *) coder {
if ([coder allowsKeyedCoding]) {
@ -37,18 +68,56 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
_maxSize = [keyed decodeSizeForKey: @"NSMaxSize"];
_minSize = [keyed decodeSizeForKey: @"NSMinSize"];
_contentMinSize = [keyed decodeSizeForKey: @"NSWindowContentMinSize"];
_contentMaxSize = [keyed decodeSizeForKey: @"NSWindowContentMaxSize"];
screenRect =
[keyed decodeRectForKey: @"NSScreenRect"]; // screen created on
_viewClass = [[keyed decodeObjectForKey: @"NSViewClass"] retain];
_wtFlags = [keyed decodeIntForKey: @"NSWTFlags"];
_windowBacking = [keyed decodeIntForKey: @"NSWindowBacking"];
_windowBacking = [keyed decodeIntegerForKey: @"NSWindowBacking"];
_windowClass = [[keyed decodeObjectForKey: @"NSWindowClass"] retain];
windowRect = [keyed decodeRectForKey: @"NSWindowRect"];
_windowStyleMask = [keyed decodeIntForKey: @"NSWindowStyleMask"];
_windowStyleMask = [keyed decodeIntegerForKey: @"NSWindowStyleMask"];
_windowTitle = [[keyed decodeObjectForKey: @"NSWindowTitle"] retain];
windowView = [[keyed decodeObjectForKey: @"NSWindowView"] retain];
_windowAutosave =
[[keyed decodeObjectForKey: @"NSFrameAutosaveName"] retain];
_collectionBehavior =
[keyed decodeIntegerForKey: @"NSWindowCollectionBehavior"];
_animationBehavior =
[keyed decodeIntegerForKey: @"NSWindowAnimationBehavior"];
_minFullScreenContentSize =
[keyed decodeSizeForKey: @"NSMinFullScreenContentSize"];
_maxFullScreenContentSize =
[keyed decodeSizeForKey: @"NSMaxFullScreenContentSize"];
_tabbingIdentifier =
[[keyed decodeObjectForKey: @"NSWindowTabbingIdentifier"]
retain];
_tabbingMode = [keyed decodeIntegerForKey: @"NSWindowTabbingMode"];
_titleVisibility =
[keyed decodeIntegerForKey: @"NSWindowTitleVisibility"];
_contentBorderThicknessForMinXEdge =
[keyed decodeDoubleForKey: @"NSContentBorderThicknessMinX"];
_contentBorderThicknessForMaxXEdge =
[keyed decodeDoubleForKey: @"NSContentBorderThicknessMaxX"];
_contentBorderThicknessForMinYEdge =
[keyed decodeDoubleForKey: @"NSContentBorderThicknessMinY"];
_contentBorderThicknessForMaxYEdge =
[keyed decodeDoubleForKey: @"NSContentBorderThicknessMaxY"];
_titlebarAppearsTransparent =
[keyed decodeBoolForKey: @"NSTitlebarAppearsTransparent"];
_autorecalculatesContentBorderThicknessForMinXEdge =
[keyed decodeBoolForKey:
@"NSAutorecalculatesContentBorderThicknessMinX"];
_autorecalculatesContentBorderThicknessForMaxXEdge =
[keyed decodeBoolForKey:
@"NSAutorecalculatesContentBorderThicknessMaxX"];
_autorecalculatesContentBorderThicknessForMinYEdge =
[keyed decodeBoolForKey:
@"NSAutorecalculatesContentBorderThicknessMinY"];
_autorecalculatesContentBorderThicknessForMaxYEdge =
[keyed decodeBoolForKey:
@"NSAutorecalculatesContentBorderThicknessMaxY"];
if ([NSScreen mainScreen])
windowRect.origin.y -= screenRect.size.height -
@ -72,13 +141,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
[windowView release];
[_windowAutosave release];
[_identifier release];
[_tabbingIdentifier release];
[_toolbar release];
[super dealloc];
}
- awakeAfterUsingCoder: (NSCoder *) coder {
NSWindow *result;
Class class;
BOOL defer;
if ((class = NSClassFromString(_windowClass)) == Nil) {
[NSException
@ -87,17 +157,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
_windowClass];
class = [NSWindow class];
}
defer = (_wtFlags & 0x20000000) ? YES : NO;
result = [[class alloc] initWithContentRect: windowRect
styleMask: _windowStyleMask
backing: _windowBacking
defer: defer];
defer: self.isDeferred];
[result setMinSize: _minSize];
[result setMaxSize: _maxSize];
[result setOneShot: (_wtFlags & 0x10000000) ? YES : NO];
[result setReleasedWhenClosed: (_wtFlags & 0x40000000) ? NO : YES];
[result setHidesOnDeactivate: (_wtFlags & 0x80000000) ? YES : NO];
[result setOneShot: self.isOneShot];
[result setReleasedWhenClosed: self.releasedWhenClosed];
[result setHidesOnDeactivate: self.hidesOnDeactivate];
[result setTitle: _windowTitle];
[result setIdentifier: _identifier];
[result setToolbar: _toolbar];
[result setContentView: windowView];
[windowView setAutoresizesSubviews: YES];
@ -123,8 +194,181 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
return nil;
}
- (void) setStyleMask: (NSUInteger) mask {
_windowStyleMask = mask;
- (id) appearance {
NSUnimplementedMethod();
return nil;
}
- (BOOL) isOneShot {
return (_wtFlags & NSWindowTemplateFlagOneShot) != 0;
}
- (void) setOneShot: (BOOL) oneShot {
if (oneShot) {
_wtFlags |= NSWindowTemplateFlagOneShot;
} else {
_wtFlags &= ~NSWindowTemplateFlagOneShot;
}
}
- (BOOL) isDeferred {
return (_wtFlags & NSWindowTemplateFlagDeferred) != 0;
}
- (void) setDeferred: (BOOL) deferred {
if (deferred) {
_wtFlags |= NSWindowTemplateFlagDeferred;
} else {
_wtFlags &= ~NSWindowTemplateFlagDeferred;
}
}
- (BOOL) isReleasedWhenClosed {
return (_wtFlags & NSWindowTemplateFlagNotReleasedWhenClosed) == 0;
}
- (void) setReleasedWhenClosed: (BOOL) releasedWhenClosed {
if (releasedWhenClosed) {
_wtFlags &= ~NSWindowTemplateFlagNotReleasedWhenClosed;
} else {
_wtFlags |= NSWindowTemplateFlagNotReleasedWhenClosed;
}
}
- (BOOL) hidesOnDeactivate {
return (_wtFlags & NSWindowTemplateFlagHidesOnDeactivate) != 0;
}
- (void) setHidesOnDeactivate: (BOOL) hidesOnDeactivate {
if (hidesOnDeactivate) {
_wtFlags |= NSWindowTemplateFlagHidesOnDeactivate;
} else {
_wtFlags &= ~NSWindowTemplateFlagHidesOnDeactivate;
}
}
- (BOOL) allowsToolTipsWhenApplicationIsInactive {
return (_wtFlags & NSWindowTemplateFlagAllowsToolTipsWhenApplicationIsInactive) != 0;
}
- (void) setAllowsToolTipsWhenApplicationIsInactive: (BOOL) allowsToolTipsWhenApplicationIsInactive {
if (allowsToolTipsWhenApplicationIsInactive) {
_wtFlags |= NSWindowTemplateFlagAllowsToolTipsWhenApplicationIsInactive;
} else {
_wtFlags &= ~NSWindowTemplateFlagAllowsToolTipsWhenApplicationIsInactive;
}
}
- (BOOL) autorecalculatesKeyViewLoop {
return (_wtFlags & NSWindowTemplateFlagAutorecalculatesKeyViewLoop) != 0;
}
- (void) setAutorecalculatesKeyViewLoop: (BOOL) autorecalculatesKeyViewLoop {
if (autorecalculatesKeyViewLoop) {
_wtFlags |= NSWindowTemplateFlagAutorecalculatesKeyViewLoop;
} else {
_wtFlags &= ~NSWindowTemplateFlagAutorecalculatesKeyViewLoop;
}
}
- (BOOL) isRestorable {
return (_wtFlags & NSWindowTemplateFlagRestorable) != 0;
}
- (void) setRestorable: (BOOL) restorable {
if (restorable) {
_wtFlags |= NSWindowTemplateFlagRestorable;
} else {
_wtFlags &= ~NSWindowTemplateFlagRestorable;
}
}
- (BOOL) hasShadow {
return (_wtFlags & NSWindowTemplateFlagNoShadow) == 0;
}
- (void) setHasShadow: (BOOL) hasShadow {
if (hasShadow) {
_wtFlags &= ~NSWindowTemplateFlagNoShadow;
} else {
_wtFlags |= NSWindowTemplateFlagNoShadow;
}
}
- (uint32_t) autoPositionMask {
return (_wtFlags & NSWindowTemplateFlagAutoPositionMask) >> NSWindowTemplateFlagAutoPositionShift;
}
- (void) setAutoPositionMask: (uint32_t) autoPositionMask {
_wtFlags = (_wtFlags & ~NSWindowTemplateFlagAutoPositionMask) | ((autoPositionMask << NSWindowTemplateFlagAutoPositionShift) & NSWindowTemplateFlagAutoPositionMask);
}
- (BOOL) wantsToBeColor {
return (_wtFlags & NSWindowTemplateFlagWantsToBeColor) != 0;
}
- (void) setWantsToBeColor: (BOOL) wantsToBeColor {
if (wantsToBeColor) {
_wtFlags |= NSWindowTemplateFlagWantsToBeColor;
} else {
_wtFlags &= ~NSWindowTemplateFlagWantsToBeColor;
}
}
- (BOOL) autorecalculatesContentBorderThicknessForEdge: (NSRectEdge) edge {
if (edge == NSRectEdgeMinX) {
return _autorecalculatesContentBorderThicknessForMinXEdge;
} else if (edge == NSRectEdgeMaxX) {
return _autorecalculatesContentBorderThicknessForMaxXEdge;
} else if (edge == NSRectEdgeMinY) {
return _autorecalculatesContentBorderThicknessForMinYEdge;
} else if (edge == NSRectEdgeMaxY) {
return _autorecalculatesContentBorderThicknessForMaxYEdge;
} else {
return NO;
}
}
- (void) setAutorecalculatesContentBorderThickness: (BOOL) autorecalculatesContentBorderThickness
forEdge: (NSRectEdge) edge
{
if (edge == NSRectEdgeMinX) {
_autorecalculatesContentBorderThicknessForMinXEdge = autorecalculatesContentBorderThickness;
} else if (edge == NSRectEdgeMaxX) {
_autorecalculatesContentBorderThicknessForMaxXEdge = autorecalculatesContentBorderThickness;
} else if (edge == NSRectEdgeMinY) {
_autorecalculatesContentBorderThicknessForMinYEdge = autorecalculatesContentBorderThickness;
} else if (edge == NSRectEdgeMaxY) {
_autorecalculatesContentBorderThicknessForMaxYEdge = autorecalculatesContentBorderThickness;
}
}
- (CGFloat) contentBorderThicknessForEdge: (NSRectEdge) edge {
if (edge == NSRectEdgeMinX) {
return _contentBorderThicknessForMinXEdge;
} else if (edge == NSRectEdgeMaxX) {
return _contentBorderThicknessForMaxXEdge;
} else if (edge == NSRectEdgeMinY) {
return _contentBorderThicknessForMinYEdge;
} else if (edge == NSRectEdgeMaxY) {
return _contentBorderThicknessForMaxYEdge;
} else {
return 0;
}
}
- (void) setContentBorderThickness: (CGFloat) contentBorderThickness
forEdge: (NSRectEdge) edge
{
if (edge == NSRectEdgeMinX) {
_contentBorderThicknessForMinXEdge = contentBorderThickness;
} else if (edge == NSRectEdgeMaxX) {
_contentBorderThicknessForMaxXEdge = contentBorderThickness;
} else if (edge == NSRectEdgeMinY) {
_contentBorderThicknessForMinYEdge = contentBorderThickness;
} else if (edge == NSRectEdgeMaxY) {
_contentBorderThicknessForMaxYEdge = contentBorderThickness;
}
}
@end