Many encodeWithCoder: implementations for Interface Builder

These are all the implementations needed for my sample app, but more
will have to be added later for XIBs with other objects, of course.
This commit is contained in:
Ariel Abreu 2023-10-13 10:33:13 -04:00
parent 86a42fbbf9
commit 80e61187d4
No known key found for this signature in database
GPG Key ID: 5B88AAAF4280706F
15 changed files with 425 additions and 36 deletions

View File

@ -36,6 +36,75 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSLocale.h>
#import <Foundation/NSNumberFormatter.h>
typedef NS_OPTIONS(unsigned int, NSCellAppleFlags) {
NSCellAppleFlagOnState = 1u << 31,
NSCellAppleFlagHighlighted = 1u << 30,
NSCellAppleFlagDisabled = 1u << 29,
NSCellAppleFlagEditable = 1u << 28,
NSCellAppleFlagTypeShift = 26,
NSCellAppleFlagTypeMask = 0x03u << NSCellAppleFlagTypeShift,
NSCellAppleFlagVerticallyCentered = 1u << 25,
NSCellAppleFlagHorizontallyCentered = 1u << 24,
NSCellAppleFlagBordered = 1u << 23,
NSCellAppleFlagBezeled = 1u << 22,
NSCellAppleFlagSelectable = 1u << 21,
NSCellAppleFlagScrollable = 1u << 20,
NSCellAppleFlagContinuous = 1u << 19,
NSCellAppleFlagActOnMouseDown = 1u << 18,
NSCellAppleFlagLeaf = 1u << 17,
NSCellAppleFlagInvalidObjectValue = 1u << 16,
NSCellAppleFlagInvalidFont = 1u << 15,
NSCellAppleFlagReserved1 = 1u << 14,
NSCellAppleFlagReserved2 = 1u << 13,
NSCellAppleFlagReserved3 = 1u << 12,
NSCellAppleFlagReserved4 = 1u << 11,
NSCellAppleFlagSingleLineMode = 1u << 10,
NSCellAppleFlagReserved5 = 1u << 9,
NSCellAppleFlagActOnMouseDrag = 1u << 8,
NSCellAppleFlagLoaded = 1u << 7,
NSCellAppleFlagTruncateLastLine = 1u << 6,
NSCellAppleFlagDontActOnMouseUp = 1u << 5,
NSCellAppleFlagWhite = 1u << 4,
NSCellAppleFlagUserKeyEquivalent = 1u << 3,
NSCellAppleFlagShowsFirstResponder = 1u << 2,
NSCellAppleFlagFocusRingTypeShift = 0,
NSCellAppleFlagFocusRingTypeMask = 0x03u << NSCellAppleFlagFocusRingTypeShift,
};
typedef NS_OPTIONS(unsigned int, NSCellAppleFlags2) {
NSCellAppleFlag2WasSelectable = 1u << 31,
NSCellAppleFlag2RichText = 1u << 30,
NSCellAppleFlag2Reserved1 = 1u << 29,
//NSCellAppleFlag2ImportsGraph = 1u << 28, // clearly wrong, since this would overlap with TextAlignmentMask
NSCellAppleFlag2TextAlignmentShift = 16,
NSCellAppleFlag2TextAlignmentMask = 0x07u << NSCellAppleFlag2TextAlignmentShift,
NSCellAppleFlag2RefusesFirstResponder = 1u << 25,
NSCellAppleFlag2AllowsMixedState = 1u << 24,
NSCellAppleFlag2InMixedState = 1u << 23,
NSCellAppleFlag2ActOnEditingEnd = 1u << 22,
NSCellAppleFlag2Reserved3 = 1u << 21,
NSCellAppleFlag2Reserved4 = 1u << 20,
NSCellAppleFlag2ControlSizeShift = 17,
NSCellAppleFlag2ControlSizeMask = 0x07u << NSCellAppleFlag2ControlSizeShift,
NSCellAppleFlag2Reserved5 = 1u << 16,
NSCellAppleFlag2Reserved6 = 1u << 15,
NSCellAppleFlag2Reserved7 = 1u << 14,
NSCellAppleFlag2Reserved8 = 1u << 13,
NSCellAppleFlag2Reserved9 = 1u << 12,
NSCellAppleFlag2Reserved10 = 1u << 11,
NSCellAppleFlag2LineBreakModeShift = 9,
NSCellAppleFlag2LineBreakModeMask = 0x03u << NSCellAppleFlag2LineBreakModeShift,
NSCellAppleFlag2Reserved11 = 1u << 8,
NSCellAppleFlag2Reserved12 = 1u << 7,
NSCellAppleFlag2Reserved13 = 1u << 6,
NSCellAppleFlag2Reserved14 = 1u << 5,
NSCellAppleFlag2Reserved15 = 1u << 4,
NSCellAppleFlag2Reserved16 = 1u << 3,
NSCellAppleFlag2Reserved17 = 1u << 2,
NSCellAppleFlag2Reserved18 = 1u << 1,
NSCellAppleFlag2Reserved19 = 1u << 0,
};
@implementation NSCell
@synthesize identifier = _identifier;
@ -60,33 +129,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#pragma mark -
- (void) encodeWithCoder: (NSCoder *) coder {
NSUnimplementedMethod();
}
- _applyAppleFlags: (unsigned int) flags flags2: (unsigned int) flags2 {
- (void) _applyAppleFlags: (unsigned int) flags flags2: (unsigned int) flags2 {
// These flags are big endian so the first flag is over on the left of the
// int
_state = (flags & 0x80000000) ? NSOnState : NSOffState;
_isHighlighted = (flags & 0x40000000) ? YES : NO;
_isEnabled = (flags & 0x20000000) ? NO : YES; // "disabled" in Cocoa
_isEditable = (flags & 0x10000000) ? YES : NO;
_cellType = (flags & 0x0C000000) >> 26;
_state = (flags & NSCellAppleFlagOnState) ? NSControlStateValueOn : NSControlStateValueOff;
_isHighlighted = (flags & NSCellAppleFlagHighlighted) ? YES : NO;
_isEnabled = (flags & NSCellAppleFlagDisabled) ? NO : YES; // "disabled" in Cocoa
_isEditable = (flags & NSCellAppleFlagEditable) ? YES : NO;
_cellType = (flags & NSCellAppleFlagTypeMask) >> NSCellAppleFlagTypeShift;
// vCentered = (flags & 0x02000000)
// hCentered = (flags & 0x01000000)
_isBordered = (flags & 0x00800000) ? YES : NO;
_isBezeled = (flags & 0x00400000) ? YES : NO;
_isSelectable = (flags & 0x00200000) ? YES : NO;
_isScrollable = (flags & 0x00100000) ? YES : NO;
_isBordered = (flags & NSCellAppleFlagBordered) ? YES : NO;
_isBezeled = (flags & NSCellAppleFlagBezeled) ? YES : NO;
_isSelectable = (flags & NSCellAppleFlagSelectable) ? YES : NO;
_isScrollable = (flags & NSCellAppleFlagScrollable) ? YES : NO;
// _wraps = (flags & 0x00100000) ? NO : YES; // ! scrollable, use
// lineBreakMode ?
// 0x00080000 = continuous
// 0x00040000 = action on mouse down
// 0x00000100 = action on mouse drag
_isContinuous = (flags & 0x00080100) ? YES : NO;
_isContinuous = (flags & (NSCellAppleFlagContinuous | NSCellAppleFlagActOnMouseDrag)) ? YES : NO;
// actOnMouseDown = (flags & 0x00040000)
// isLeaf = (flags & 0x00020000)
@ -105,7 +170,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// userKeyEquiv = (flags & 0x00000008)
// showsFirstResp= (flags & 0x00000004)
_focusRingType = (flags & 0x00000003);
_focusRingType = (flags & NSCellAppleFlagFocusRingTypeMask) >> NSCellAppleFlagFocusRingTypeShift;
// Now for flags2 - the layout of these flags seems to be more
// random. So the best way to find out which bit(s) you need is
@ -114,28 +179,79 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// NSCellFlags2 value to hex
// wasSelectable = (flags2 & 0x80000000)
_isRichText = (flags2 & 0x40000000) ? YES : NO;
_isRichText = (flags2 & NSCellAppleFlag2RichText) ? YES : NO;
// importsGraph = (flags2 & 0x10000000)
_textAlignment = (flags2 & 0x1c000000) >> 26;
_textAlignment = (flags2 & NSCellAppleFlag2TextAlignmentMask) >> NSCellAppleFlag2TextAlignmentShift;
// layoutDirRTL = (flags2 & 0x01000000)
_writingDirection = NSWritingDirectionNatural;
// backgrdStyle = (flags2 & 0x00c00000) >> 21;
// cellReserved = (flags2 & 0x003c0000)
_refusesFirstResponder = (flags2 & 0x02000000) ? YES : NO;
_allowsMixedState = (flags2 & 0x01000000) ? YES : NO;
_refusesFirstResponder = (flags2 & NSCellAppleFlag2RefusesFirstResponder) ? YES : NO;
_allowsMixedState = (flags2 & NSCellAppleFlag2AllowsMixedState) ? YES : NO;
// inMixedState = (flags2 & 0x00800000)
_sendsActionOnEndEditing = (flags2 & 0x00400000) ? YES : NO;
_sendsActionOnEndEditing = (flags2 & NSCellAppleFlag2ActOnEditingEnd) ? YES : NO;
// Odd this isn't in flags - it's near other items in flags in the Cocoa
// struct from which these are derived.
_lineBreakMode = (flags2 & 0x00000600) >> 9 & 0x7;
_controlSize = (flags2 & 0x000E0000) >> 17;
_lineBreakMode = (flags2 & NSCellAppleFlag2LineBreakModeMask) >> NSCellAppleFlag2LineBreakModeShift;
_controlSize = (flags2 & NSCellAppleFlag2ControlSizeMask) >> NSCellAppleFlag2ControlSizeShift;
}
- (void) _generateAppleFlags: (unsigned int *) flags flags2: (unsigned int *) flags2 {
*flags = 0;
*flags2 = 0;
if (_state == NSControlStateValueOn)
*flags |= NSCellAppleFlagOnState;
else if (_state == NSControlStateValueMixed)
*flags2 |= NSCellAppleFlag2InMixedState;
if (_isHighlighted)
*flags |= NSCellAppleFlagHighlighted;
if (!_isEnabled)
*flags |= NSCellAppleFlagDisabled;
if (_isEditable)
*flags |= NSCellAppleFlagEditable;
*flags |= (_cellType << NSCellAppleFlagTypeShift) & NSCellAppleFlagTypeMask;
if (_isBordered)
*flags |= NSCellAppleFlagBordered;
if (_isBezeled)
*flags |= NSCellAppleFlagBezeled;
if (_isSelectable)
*flags |= NSCellAppleFlagSelectable;
if (_isScrollable)
*flags |= NSCellAppleFlagScrollable;
// we don't really store whether it's continuous or mouse drag, so assume it's continuous
if (_isContinuous)
*flags |= NSCellAppleFlagContinuous;
*flags |= (_focusRingType << NSCellAppleFlagFocusRingTypeShift) & NSCellAppleFlagFocusRingTypeMask;
if (_isRichText)
*flags2 |= NSCellAppleFlag2RichText;
*flags2 |= (_textAlignment << NSCellAppleFlag2TextAlignmentShift) & NSCellAppleFlag2TextAlignmentMask;
if (_refusesFirstResponder)
*flags2 |= NSCellAppleFlag2RefusesFirstResponder;
if (_allowsMixedState)
*flags2 |= NSCellAppleFlag2AllowsMixedState;
if (_sendsActionOnEndEditing)
*flags2 |= NSCellAppleFlag2ActOnEditingEnd;
*flags2 |= (_lineBreakMode << NSCellAppleFlag2LineBreakModeShift) & NSCellAppleFlag2LineBreakModeMask;
*flags2 |= (_controlSize << NSCellAppleFlag2ControlSizeShift) & NSCellAppleFlag2ControlSizeMask;
}
- initWithCoder: (NSCoder *) coder {
@ -222,6 +338,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
return self;
}
- (void) encodeWithCoder: (NSCoder *) coder {
unsigned int flags = 0;
unsigned int flags2 = 0;
[self _generateAppleFlags: &flags flags2: &flags2];
if (coder.allowsKeyedCoding) {
[coder encodeInt: flags forKey: @"NSCellFlags"];
[coder encodeInt: flags2 forKey: @"NSCellFlags2"];
[coder encodeObject: _objectValue forKey: @"NSContents"];
if (_image != nil) {
[coder encodeObject: _image forKey: @"NSNormalImage"];
if (_font != nil)
[coder encodeObject: _font forKey: @"NSSupport"];
} else if (_font != nil)
[coder encodeObject: _font forKey: @"NSNormalImage"];
[coder encodeObject: _formatter forKey: @"NSFormatter"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSCell"];
}
}
- initTextCell: (NSString *) string {
_focusRingType = [[self class] defaultFocusRingType];
_state = NSOffState;

View File

@ -62,7 +62,19 @@ static NSMutableDictionary *cellClassDictionary = nil;
- (void) encodeWithCoder: (NSCoder *) coder {
[super encodeWithCoder: coder];
[coder encodeObject: _cell forKey: @"NSControl cell"];
if (coder.allowsKeyedCoding) {
[coder encodeObject: _cell forKey: @"NSCell"];
[coder encodeInteger: _aux.tag forKey: @"NSTag"];
[coder encodeObject: _aux.target forKey: @"NSControlTarget"];
if (_aux.action != NULL) {
[coder encodeObject: NSStringFromSelector(_aux.action)
forKey: @"NSControlAction"];
}
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSControl"];
}
}
- initWithCoder: (NSCoder *) coder {

View File

@ -30,7 +30,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
@implementation NSResponder
- (void) encodeWithCoder: (NSCoder *) encoder {
- (void) encodeWithCoder: (NSCoder *) coder {
if (coder.allowsKeyedCoding) {
[coder encodeObject: _nextResponder forKey: @"NSNextResponder"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSResponder"];
}
}
- initWithCoder: (NSCoder *) coder {

View File

@ -82,6 +82,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
return self;
}
- (void) encodeWithCoder: (NSCoder *) coder {
[super encodeWithCoder: coder];
if (coder.allowsKeyedCoding) {
[coder encodeObject: _delegate forKey: @"NSDelegate"];
[coder encodeObject: NSStringFromSelector(_errorAction)
forKey: @"NSErrorAction"];
[coder encodeDouble: _preferredMaxLayoutWidth
forKey: @"NSPreferredMaxLayoutWidth"];
// TODO
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSTextField"];
}
}
- initWithFrame: (NSRect) frame {
[super initWithFrame: frame];
// Default for a NSTextFieldCell is NOT the same as NSTextField

View File

@ -38,7 +38,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
@synthesize allowedInputSourceLocales = _allowedInputSourceLocales;
- (void) encodeWithCoder: (NSCoder *) coder {
NSUnimplementedMethod();
[super encodeWithCoder: coder];
if (coder.allowsKeyedCoding) {
[coder encodeBool: _drawsBackground forKey: @"NSDrawsBackground"];
[coder encodeObject: _backgroundColor forKey: @"NSBackgroundColor"];
[coder encodeObject: _textColor forKey: @"NSTextColor"];
[coder encodeInteger: _bezelStyle forKey: @"NSTextBezelStyle"];
[coder encodeObject: _placeholder forKey: @"NSPlaceholderString"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSTextFieldCell"];
}
}
- initWithCoder: (NSCoder *) coder {

View File

@ -103,10 +103,6 @@ static BOOL NSShowAllViews = NO;
return 0;
}
- (void) encodeWithCoder: (NSCoder *) coder {
NSUnimplementedMethod();
}
typedef struct __VFlags {
#ifdef __BIG_ENDIAN__
unsigned int rotatedFromBase : 1;
@ -157,6 +153,43 @@ typedef struct __VFlags {
#endif
} _VFlags;
- (void) encodeWithCoder: (NSCoder *) coder {
[super encodeWithCoder: coder];
if (coder.allowsKeyedCoding) {
unsigned vFlags = 0;
vFlags |= _autoresizingMask & 0x3f;
vFlags |= _autoresizesSubviews ? 0x100 : 0;
vFlags |= _isHidden ? 0x80000000 : 0;
// TODO: there are almost certainly more vFlags
[coder encodeInt: vFlags forKey: @"NSvFlags"];
[coder encodeRect: _frame forKey: @"NSFrame"];
[coder encodeRect: _bounds forKey: @"NSBounds"];
[coder encodeInt: _tag forKey: @"NSTag"];
// TODO: do we need to order the subviews here in back-to-front order ourselves?
[coder encodeObject: _subviews forKey: @"NSSubviews"];
[coder encodeObject: _window forKey: @"NSWindow"];
[coder encodeObject: _superview forKey: @"NSSuperview"];
[coder encodeObject: _nextKeyView forKey: @"NSNextKeyView"];
[coder encodeObject: _shadow forKey: @"NSViewShadow"];
[coder encodeObject: _compositingFilter
forKey: @"NSViewCompositeFilter"];
//[coder encodeObject: _backgroundFilters
// forKey: @"NSViewBackgroundFilters"];
[coder encodeObject: _animations forKey: @"NSViewAnimations"];
//[coder encodeBool: _canDrawConcurrently
// forKey: @"NSViewCanDrawConcurrently"];
[coder encodeBool: _wantsLayer forKey: @"NSViewIsLayerTreeHost"];
[coder encodeInteger: _layerContentsRedrawPolicy
forKey: @"NSViewLayerContentsRedrawPolicy"];
[coder encodeObject: _contentFilters forKey: @"NSViewContentFilters"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSView"];
}
}
- initWithCoder: (NSCoder *) coder {
[super initWithCoder: coder];

View File

@ -19,7 +19,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
@interface NSClassSwapper : NSObject {
@interface NSClassSwapper : NSObject <NSCoding> {
NSString *_originalClassName;
NSString *_className;
id _object;

View File

@ -85,7 +85,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
}
- (void) encodeWithCoder: (NSCoder *) coder {
NSUnimplementedMethod();
if (coder.allowsKeyedCoding) {
[coder encodeObject: _className forKey: @"NSClassName"];
[coder encodeObject: _originalClassName forKey: @"NSOriginalClassName"];
[_object encodeWithCoder: coder];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSClassSwapper"];
}
}
@end

View File

@ -19,7 +19,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
@interface NSCustomObject : NSObject {
@interface NSCustomObject : NSObject <NSCoding> {
NSString *_className;
id extension;
}

View File

@ -68,6 +68,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
return self;
}
- (void) encodeWithCoder: (NSCoder *) coder {
if (coder.allowsKeyedCoding) {
[coder encodeObject: _className forKey: @"NSClassName"];
[coder encodeObject: extension forKey: @"NSExtension"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSCustomObject"];
}
}
- (void) dealloc {
[_className release];
[self->extension release];

View File

@ -21,7 +21,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
@class NSArray, NSCustomObject, NSSet, NSDictionary, NSMenu;
@interface NSIBObjectData : NSObject {
@interface NSIBObjectData : NSObject <NSCoding> {
NSMapTable *_nameTable;
NSArray *_accessibilityConnectors;
NSMapTable *_classTable;

View File

@ -387,6 +387,100 @@ NSString *const IBCocoaFramework = @"IBCocoaFramework";
return self;
}
- (NSArray *) _sortedAndFilteredMapTableKeys: (NSMapTable *) mapTable {
NSMutableArray *initialKeys = [[NSAllMapTableKeys(mapTable) mutableCopy] autorelease];
// remove the firstResponder from the key array, if present.
// it's never included in the encoded output.
if (_firstResponder != nil) {
[initialKeys removeObjectIdenticalTo: _firstResponder];
}
// we need map table entries to be sorted in OID order.
// not sure if it's important, but that's what i've seen in NIBs so that's what we'll do.
return [initialKeys sortedArrayWithOptions: NSSortStable usingComparator: ^NSComparisonResult(id key1, id key2) {
// the OID table uses integers directly as values, so we have to use the C API instead of the ObjC API
NSUInteger oid1 = (NSUInteger)NSMapGet(_oidTable, key1);
NSUInteger oid2 = (NSUInteger)NSMapGet(_oidTable, key2);
if (oid1 > oid2) {
return NSOrderedDescending;
} else if (oid1 < oid2) {
return NSOrderedAscending;
} else {
// this shouldn't happen
return NSOrderedSame;
}
}];
}
- (void) _encodeObjectMapTable: (NSMapTable *) objectMapTable
withCoder: (NSCoder *) coder
keysName: (NSString *) keyName
valuesName: (NSString *) valueName
{
// all map tables entries are encoded in ascending order according to their OID
NSArray *keys = [self _sortedAndFilteredMapTableKeys: objectMapTable];
NSMutableArray *values = [NSMutableArray arrayWithCapacity: keys.count];
for (id key in keys) {
[values addObject: [objectMapTable objectForKey: key]];
}
[coder encodeObject: keys forKey: keyName];
[coder encodeObject: values forKey: valueName];
}
- (void) encodeWithCoder: (NSCoder *) coder {
if (coder.allowsKeyedCoding) {
// we can't use `_encodeObjectMapTable` to encode the OID table since its values aren't objects
NSArray *oidKeys = [self _sortedAndFilteredMapTableKeys: _oidTable];
NSMutableArray *oidValues = [NSMutableArray arrayWithCapacity: oidKeys.count];
for (id oidKey in oidKeys) {
[oidValues addObject: [NSNumber numberWithInteger: (NSUInteger)NSMapGet(_oidTable, oidKey)]];
}
NSArray *oidValuesImmutable = [[oidValues copy] autorelease];
[coder encodeObject: oidKeys forKey: @"NSOidsKeys"];
[coder encodeObject: oidValuesImmutable forKey: @"NSOidsValues"];
[self _encodeObjectMapTable: _objectTable
withCoder: coder
keysName: @"NSObjectsKeys"
valuesName: @"NSObjectsValues"];
[coder encodeObject: _fileOwner forKey: @"NSRoot"];
[coder encodeObject: _accessibilityConnectors forKey: @"NSAccessibilityConnectors"];
// just encode empty arrays here for now
[coder encodeObject: [NSArray array] forKey: @"NSAccessibilityOidsKeys"];
[coder encodeObject: [NSArray array] forKey: @"NSAccessibilityOidsValues"];
// note that these *have* to be encoded as mutable arrays
[coder encodeObject: _connections forKey: @"NSConnections"];
[coder encodeObject: _visibleWindows forKey: @"NSVisibleWindows"];
// this is all considered "design-time" data and only encoded if `shouldEncodeDesigntimeData` is true.
if (self.shouldEncodeDesigntimeData) {
[self _encodeObjectMapTable: _nameTable
withCoder: coder
keysName: @"NSNamesKeys"
valuesName: @"NSNamesValues"];
[self _encodeObjectMapTable: _classTable
withCoder: coder
keysName: @"NSClassesKeys"
valuesName: @"NSClassesValues"];
[coder encodeObject: _fontManager forKey: @"NSFontManager"];
[coder encodeObject: _framework forKey: @"NSFramework"];
[coder encodeInt64: _nextOid forKey: @"NSNextOid"];
}
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSIBObjectData"];
}
}
- (void) dealloc {
[_accessibilityConnectors release];
[_classTable release];

View File

@ -24,7 +24,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
@implementation NSNibConnector
- (void) encodeWithCoder: (NSCoder *) coder {
NSUnimplementedMethod();
if (coder.allowsKeyedCoding) {
[coder encodeObject: _source forKey: @"NSSource"];
[coder encodeObject: _destination forKey: @"NSDestination"];
[coder encodeObject: _label forKey: @"NSLabel"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSNibConnector"];
}
}
- initWithCoder: (NSCoder *) coder {

View File

@ -40,7 +40,7 @@ typedef NS_OPTIONS(uint32_t, NSWindowTemplateFlags) {
NSWindowTemplateFlagHidesOnDeactivate = 1u << 31,
};
@interface NSWindowTemplate : NSObject <NSUserInterfaceItemIdentification> {
@interface NSWindowTemplate : NSObject <NSUserInterfaceItemIdentification, NSCoding> {
// the ivars without a `_` prefix are like that because Xcode
// requires them to be named like that.

View File

@ -146,6 +146,59 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
[super dealloc];
}
- (void) encodeWithCoder: (NSCoder *) coder {
if (coder.allowsKeyedCoding) {
[coder encodeSize: _maxSize forKey: @"NSMaxSize"];
[coder encodeSize: _minSize forKey: @"NSMinSize"];
[coder encodeSize: _contentMinSize forKey: @"NSWindowContentMinSize"];
[coder encodeSize: _contentMaxSize forKey: @"NSWindowContentMaxSize"];
[coder encodeRect: screenRect forKey: @"NSScreenRect"];
[coder encodeObject: _viewClass forKey: @"NSViewClass"];
[coder encodeInt: _wtFlags forKey: @"NSWTFlags"];
[coder encodeInteger: _windowBacking forKey: @"NSWindowBacking"];
[coder encodeObject: _windowClass forKey: @"NSWindowClass"];
[coder encodeRect: windowRect forKey: @"NSWindowRect"];
[coder encodeInteger: _windowStyleMask forKey: @"NSWindowStyleMask"];
[coder encodeObject: _windowTitle forKey: @"NSWindowTitle"];
[coder encodeObject: windowView forKey: @"NSWindowView"];
[coder encodeObject: _windowAutosave forKey: @"NSFrameAutosaveName"];
[coder encodeInteger: _collectionBehavior
forKey: @"NSWindowCollectionBehavior"];
[coder encodeInteger: _animationBehavior
forKey: @"NSWindowAnimationBehavior"];
[coder encodeSize: _minFullScreenContentSize
forKey: @"NSMinFullScreenContentSize"];
[coder encodeSize: _maxFullScreenContentSize
forKey: @"NSMaxFullScreenContentSize"];
[coder encodeObject: _tabbingIdentifier
forKey: @"NSWindowTabbingIdentifier"];
[coder encodeInteger: _tabbingMode forKey: @"NSWindowTabbingMode"];
[coder encodeInteger: _titleVisibility
forKey: @"NSWindowTitleVisibility"];
[coder encodeDouble: _contentBorderThicknessForMinXEdge
forKey: @"NSContentBorderThicknessMinX"];
[coder encodeDouble: _contentBorderThicknessForMaxXEdge
forKey: @"NSContentBorderThicknessMaxX"];
[coder encodeDouble: _contentBorderThicknessForMinYEdge
forKey: @"NSContentBorderThicknessMinY"];
[coder encodeDouble: _contentBorderThicknessForMaxYEdge
forKey: @"NSContentBorderThicknessMaxY"];
[coder encodeBool: _titlebarAppearsTransparent
forKey: @"NSTitlebarAppearsTransparent"];
[coder encodeBool: _autorecalculatesContentBorderThicknessForMinXEdge
forKey: @"NSAutorecalculatesContentBorderThicknessMinX"];
[coder encodeBool: _autorecalculatesContentBorderThicknessForMaxXEdge
forKey: @"NSAutorecalculatesContentBorderThicknessMaxX"];
[coder encodeBool: _autorecalculatesContentBorderThicknessForMinYEdge
forKey: @"NSAutorecalculatesContentBorderThicknessMinY"];
[coder encodeBool: _autorecalculatesContentBorderThicknessForMaxYEdge
forKey: @"NSAutorecalculatesContentBorderThicknessMaxY"];
} else {
[NSException raise: NSInvalidArchiveOperationException
format: @"TODO: support unkeyed encoding in NSWindowTemplate"];
}
}
- awakeAfterUsingCoder: (NSCoder *) coder {
NSWindow *result;
Class class;