diff --git a/ChangeLog b/ChangeLog index b10031338..c95b82d39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-06-04 12:28 Gregory John Casamento + + * Source/GSTrackingRect.m: Encode, if not a keyed archiver. + * Source/NSApplication.m: Added coding + * Source/NSDataLink.m: Added coding + * Source/NSDataLinkManager.m: Added coding + * Source/NSNib.m: Made comment use "TODO_NIB" instead of TODO, so that + it can be pulled later. + * Source/NSParagraphStyle.m: Added TODO_NIB. + * Source/NSSelection.m: Added coding. + * Source/NSSound.m: Added TODO_NIB + * Source/NSTextAttachment.m: Added TODO_NIB. + 2006-06-04 01:09 Gregory John Casamento * Source/GSHbox.m: Implemented keyed coding. diff --git a/Source/GSTrackingRect.m b/Source/GSTrackingRect.m index 2f52c2bcc..6a65d45e2 100644 --- a/Source/GSTrackingRect.m +++ b/Source/GSTrackingRect.m @@ -115,23 +115,29 @@ */ - (void) encodeWithCoder: (NSCoder*)aCoder { - BOOL inside = flags.inside; - - [aCoder encodeRect: rectangle]; - [aCoder encodeValueOfObjCType: @encode(NSTrackingRectTag) at: &tag]; - [aCoder encodeObject: owner]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &inside]; + if([aCoder allowsKeyedCoding] == NO) + { + BOOL inside = flags.inside; + + [aCoder encodeRect: rectangle]; + [aCoder encodeValueOfObjCType: @encode(NSTrackingRectTag) at: &tag]; + [aCoder encodeObject: owner]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &inside]; + } } - (id) initWithCoder: (NSCoder*)aDecoder { - BOOL inside; - - rectangle = [aDecoder decodeRect]; - [aDecoder decodeValueOfObjCType: @encode(NSTrackingRectTag) at: &tag]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &owner]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &inside]; - flags.inside = inside; + if([aDecoder allowsKeyedCoding] == NO) + { + BOOL inside; + + rectangle = [aDecoder decodeRect]; + [aDecoder decodeValueOfObjCType: @encode(NSTrackingRectTag) at: &tag]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &owner]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &inside]; + flags.inside = inside; + } return self; } diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 9f52ccacf..255e3914b 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -3292,10 +3292,18 @@ image.

See Also: -applicationIconImage

- (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; - - [aCoder encodeConditionalObject: _delegate]; - [aCoder encodeObject: _main_menu]; - [aCoder encodeConditionalObject: _windows_menu]; + if([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _delegate forKey: @"NSDelegate"]; + [aCoder encodeObject: _main_menu forKey: @"NSMainMenu"]; // ??? + [aCoder encodeObject: _windows_menu forKey: @"NSWindowsMenu"]; // ??? + } + else + { + [aCoder encodeConditionalObject: _delegate]; + [aCoder encodeObject: _main_menu]; + [aCoder encodeConditionalObject: _windows_menu]; + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -3303,13 +3311,27 @@ image.

See Also: -applicationIconImage

id obj; [super initWithCoder: aDecoder]; - - obj = [aDecoder decodeObject]; - [self setDelegate: obj]; - obj = [aDecoder decodeObject]; - [self setMainMenu: obj]; - obj = [aDecoder decodeObject]; - [self setWindowsMenu: obj]; + if([aDecoder allowsKeyedCoding]) + { + if([aDecoder containsValueForKey: @"NSDelegate"]) + { + obj = [aDecoder decodeObjectForKey: @"NSDelegate"]; + } + [self setDelegate: obj]; + obj = [aDecoder decodeObjectForKey: @"NSMainMenu"]; // TODO_NIB: Verify this key!! + [self setMainMenu: obj]; + obj = [aDecoder decodeObjectForKey: @"NSWindowsMenu"]; // TODO_NIB: Verify this key!! + [self setWindowsMenu: obj]; + } + else + { + obj = [aDecoder decodeObject]; + [self setDelegate: obj]; + obj = [aDecoder decodeObject]; + [self setMainMenu: obj]; + obj = [aDecoder decodeObject]; + [self setWindowsMenu: obj]; + } return self; } diff --git a/Source/NSDataLink.m b/Source/NSDataLink.m index 7c5a22379..f67a5cce8 100644 --- a/Source/NSDataLink.m +++ b/Source/NSDataLink.m @@ -269,79 +269,154 @@ - (void) encodeWithCoder: (NSCoder*)aCoder { BOOL flag = NO; + + if([aCoder allowsKeyedCoding]) + { + [aCoder encodeInt: linkNumber forKey: @"GSLinkNumber"]; + [aCoder encodeInt: disposition forKey: @"GSUpdateMode"]; + [aCoder encodeInt: updateMode forKey: @"GSLastUpdateMode"]; - [aCoder encodeValueOfObjCType: @encode(int) at: &linkNumber]; - [aCoder encodeValueOfObjCType: @encode(int) at: &disposition]; - [aCoder encodeValueOfObjCType: @encode(int) at: &updateMode]; - [aCoder encodeValueOfObjCType: @encode(id) at: &lastUpdateTime]; + [aCoder encodeObject: lastUpdateTime forKey: @"GSLastUpdateTime"]; - [aCoder encodeValueOfObjCType: @encode(id) at: &sourceApplicationName]; - [aCoder encodeValueOfObjCType: @encode(id) at: &sourceFilename]; - [aCoder encodeValueOfObjCType: @encode(id) at: &sourceSelection]; - [aCoder encodeValueOfObjCType: @encode(id) at: &sourceManager]; + [aCoder encodeObject: sourceApplicationName forKey: @"GSSourceApplicationName"]; + [aCoder encodeObject: sourceFilename forKey: @"GSSourceFilename"]; + [aCoder encodeObject: sourceSelection forKey: @"GSSourceSelection"]; + [aCoder encodeObject: sourceManager forKey: @"GSSourceManager"]; - [aCoder encodeValueOfObjCType: @encode(id) at: &destinationApplicationName]; - [aCoder encodeValueOfObjCType: @encode(id) at: &destinationFilename]; - [aCoder encodeValueOfObjCType: @encode(id) at: &destinationSelection]; - [aCoder encodeValueOfObjCType: @encode(id) at: &destinationManager]; - - [aCoder encodeValueOfObjCType: @encode(id) at: &types]; - - // flags... - flag = _flags.appVerifies; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.canUpdateContinuously; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.isDirty; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.willOpenSource; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.willUpdate; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + [aCoder encodeObject: destinationApplicationName forKey: @"GSDestinationApplicationName"]; + [aCoder encodeObject: destinationFilename forKey: @"GSDestinationFilename"]; + [aCoder encodeObject: destinationSelection forKey: @"GSDestinationSelection"]; + [aCoder encodeObject: destinationManager forKey: @"GSDestinationManager"]; + + [aCoder encodeObject: types forKey: @"GSTypes"]; + + // flags... + flag = _flags.appVerifies; + [aCoder encodeBool: flag forKey: @"GSAppVerifies"]; + flag = _flags.canUpdateContinuously; + [aCoder encodeBool: flag forKey: @"GSCanUpdateContinuously"]; + flag = _flags.isDirty; + [aCoder encodeBool: flag forKey: @"GSIsDirty"]; + flag = _flags.willOpenSource; + [aCoder encodeBool: flag forKey: @"GSWillOpenSource"]; + flag = _flags.willUpdate; + [aCoder encodeBool: flag forKey: @"GSWillUpdate"]; + } + else + { + [aCoder encodeValueOfObjCType: @encode(int) at: &linkNumber]; + [aCoder encodeValueOfObjCType: @encode(int) at: &disposition]; + [aCoder encodeValueOfObjCType: @encode(int) at: &updateMode]; + [aCoder encodeValueOfObjCType: @encode(id) at: &lastUpdateTime]; + + [aCoder encodeValueOfObjCType: @encode(id) at: &sourceApplicationName]; + [aCoder encodeValueOfObjCType: @encode(id) at: &sourceFilename]; + [aCoder encodeValueOfObjCType: @encode(id) at: &sourceSelection]; + [aCoder encodeValueOfObjCType: @encode(id) at: &sourceManager]; + + [aCoder encodeValueOfObjCType: @encode(id) at: &destinationApplicationName]; + [aCoder encodeValueOfObjCType: @encode(id) at: &destinationFilename]; + [aCoder encodeValueOfObjCType: @encode(id) at: &destinationSelection]; + [aCoder encodeValueOfObjCType: @encode(id) at: &destinationManager]; + + [aCoder encodeValueOfObjCType: @encode(id) at: &types]; + + // flags... + flag = _flags.appVerifies; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.canUpdateContinuously; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.isDirty; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.willOpenSource; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.willUpdate; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + } } - (id) initWithCoder: (NSCoder*)aCoder { - int version = [aCoder versionForClassName: @"NSDataLink"]; - - if (version == 0) + if([aCoder allowsKeyedCoding]) { - BOOL flag = NO; + id obj; - [aCoder decodeValueOfObjCType: @encode(int) at: &linkNumber]; - [aCoder decodeValueOfObjCType: @encode(int) at: &disposition]; - [aCoder decodeValueOfObjCType: @encode(int) at: &updateMode]; - [aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager]; - [aCoder encodeValueOfObjCType: @encode(id) at: &destinationManager]; - [aCoder decodeValueOfObjCType: @encode(id) at: &lastUpdateTime]; + linkNumber = [aCoder decodeObjectForKey: @"GSLinkNumber"]; + disposition = [aCoder decodeIntForKey: @"GSDisposition"]; + updateMode = [aCoder decodeIntForKey: @"GSUpdateMode"]; - [aCoder decodeValueOfObjCType: @encode(id) at: &sourceApplicationName]; - [aCoder decodeValueOfObjCType: @encode(id) at: &sourceFilename]; - [aCoder decodeValueOfObjCType: @encode(id) at: &sourceSelection]; - [aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager]; - - [aCoder decodeValueOfObjCType: @encode(id) at: &destinationApplicationName]; - [aCoder decodeValueOfObjCType: @encode(id) at: &destinationFilename]; - [aCoder decodeValueOfObjCType: @encode(id) at: &destinationSelection]; - [aCoder decodeValueOfObjCType: @encode(id) at: &destinationManager]; - - [aCoder decodeValueOfObjCType: @encode(id) at: &types]; + obj = [aCoder decodeObjectForKey: @"GSSourceManager"]; + ASSIGN(sourceManager,obj); + obj = [aCoder decodeObjectForKey: @"GSDestinationManager"]; + ASSIGN(destinationManager,obj); + obj = [aCoder decodeObjectForKey: @"GSLastUpdateTime"]; + ASSIGN(lastUpdateTime, obj); + obj = [aCoder decodeObjectForKey: @"GSSourceApplicationName"]; + ASSIGN(sourceApplicationName,obj); + obj = [aCoder decodeObjectForKey: @"GSSourceFilename"]; + ASSIGN(sourceFilename,obj); + obj = [aCoder decodeObjectForKey: @"GSSourceSelection"]; + ASSIGN(sourceSelection,obj); + obj = [aCoder decodeObjectForKey: @"GSSourceManager"]; + ASSIGN(sourceManager,obj); + obj = [aCoder decodeObjectForKey: @"GSDestinationApplicationName"]; + ASSIGN(destinationApplicationName,obj); + obj = [aCoder decodeObjectForKey: @"GSDestinationFilename"]; + ASSIGN(destinationFilename,obj); + obj = [aCoder decodeObjectForKey: @"GSDestinationSelection"]; + ASSIGN(destinationSelection,obj); + obj = [aCoder decodeObjectForKey: @"GSDestinationManager"]; + ASSIGN(destinationManager,obj); + obj = [aCoder decodeObjectForKey: @"GSTypes"]; + ASSIGN(types,obj); // flags... - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; - _flags.appVerifies = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; - _flags.canUpdateContinuously = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; - _flags.isDirty = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; - _flags.willOpenSource = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; - _flags.willUpdate = flag; + _flags.appVerifies = [aCoder decodeBoolForKey: @"GSAppVerifies"]; + _flags.canUpdateContinuously = [aCoder decodeBoolForKey: @"GSCanUpdateContinuously"]; + _flags.isDirty = [aCoder decodeBoolForKey: @"GSIsDirty"]; + _flags.willOpenSource = [aCoder decodeBoolForKey: @"GSWillOpenSource"]; + _flags.willUpdate = [aCoder decodeBoolForKey: @"GSWillUpdate"]; } else { - return nil; + int version = [aCoder versionForClassName: @"NSDataLink"]; + if (version == 0) + { + BOOL flag = NO; + + [aCoder decodeValueOfObjCType: @encode(int) at: &linkNumber]; + [aCoder decodeValueOfObjCType: @encode(int) at: &disposition]; + [aCoder decodeValueOfObjCType: @encode(int) at: &updateMode]; + [aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager]; + [aCoder decodeValueOfObjCType: @encode(id) at: &destinationManager]; + [aCoder decodeValueOfObjCType: @encode(id) at: &lastUpdateTime]; + + [aCoder decodeValueOfObjCType: @encode(id) at: &sourceApplicationName]; + [aCoder decodeValueOfObjCType: @encode(id) at: &sourceFilename]; + [aCoder decodeValueOfObjCType: @encode(id) at: &sourceSelection]; + [aCoder decodeValueOfObjCType: @encode(id) at: &sourceManager]; + + [aCoder decodeValueOfObjCType: @encode(id) at: &destinationApplicationName]; + [aCoder decodeValueOfObjCType: @encode(id) at: &destinationFilename]; + [aCoder decodeValueOfObjCType: @encode(id) at: &destinationSelection]; + [aCoder decodeValueOfObjCType: @encode(id) at: &destinationManager]; + + [aCoder decodeValueOfObjCType: @encode(id) at: &types]; + + // flags... + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.appVerifies = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.canUpdateContinuously = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.isDirty = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.willOpenSource = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.willUpdate = flag; + } + else + return nil; } return self; diff --git a/Source/NSDataLinkManager.m b/Source/NSDataLinkManager.m index 77d0b6298..a5c741aad 100644 --- a/Source/NSDataLinkManager.m +++ b/Source/NSDataLinkManager.m @@ -333,46 +333,84 @@ { BOOL flag = NO; - [aCoder encodeValueOfObjCType: @encode(id) at: &filename]; - [aCoder encodeValueOfObjCType: @encode(id) at: &sourceLinks]; - [aCoder encodeValueOfObjCType: @encode(id) at: &destinationLinks]; - - flag = _flags.areLinkOutlinesVisible; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.delegateVerifiesLinks; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.interactsWithUser; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; - flag = _flags.isEdited; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + if([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: filename forKey: @"GSFilename"]; + [aCoder encodeObject: sourceLinks forKey: @"GSSourceLinks"]; + [aCoder encodeObject: destinationLinks forKey: @"GSDestinationLinks"]; + + flag = _flags.areLinkOutlinesVisible; + [aCoder encodeBool: flag forKey: @"GSAreLinkOutlinesVisible"]; + flag = _flags.delegateVerifiesLinks; + [aCoder encodeBool: flag forKey: @"GSDelegateVerifiesLinks"]; + flag = _flags.interactsWithUser; + [aCoder encodeBool: flag forKey: @"GSInteractsWithUser"]; + flag = _flags.isEdited; + [aCoder encodeBool: flag forKey: @"GSIsEdited"]; + } + else + { + [aCoder encodeValueOfObjCType: @encode(id) at: &filename]; + [aCoder encodeValueOfObjCType: @encode(id) at: &sourceLinks]; + [aCoder encodeValueOfObjCType: @encode(id) at: &destinationLinks]; + + flag = _flags.areLinkOutlinesVisible; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.delegateVerifiesLinks; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.interactsWithUser; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = _flags.isEdited; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; + } } - (id) initWithCoder: (NSCoder*)aCoder { - int version = [aCoder versionForClassName: @"NSDataLinkManager"]; - - if (version == 0) + if([aCoder allowsKeyedCoding]) { BOOL flag = NO; + id obj; + + obj = [aCoder decodeObjectForKey: @"GSFilename"]; + ASSIGN(filename,obj); + obj = [aCoder decodeObjectForKey: @"GSSourceLinks"]; + ASSIGN(sourceLinks,obj); + obj = [aCoder decodeObjectForKey: @"GSDestinationLinks"]; + ASSIGN(destinationLinks,obj); - [aCoder decodeValueOfObjCType: @encode(id) at: &filename]; - [aCoder decodeValueOfObjCType: @encode(id) at: &sourceLinks]; - [aCoder decodeValueOfObjCType: @encode(id) at: &destinationLinks]; - - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = [aCoder decodeBoolForKey: @"GSAreLinkOutlinesVisible"]; _flags.areLinkOutlinesVisible = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = [aCoder decodeBoolForKey: @"GSDelegateVerifiesLinks"]; _flags.delegateVerifiesLinks = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = [aCoder decodeBoolForKey: @"GSInteractsWithUser"]; _flags.interactsWithUser = flag; - [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + flag = [aCoder decodeBoolForKey: @"GSIsEdited"]; _flags.isEdited = flag; } else { - return nil; + int version = [aCoder versionForClassName: @"NSDataLinkManager"]; + if (version == 0) + { + BOOL flag = NO; + + [aCoder decodeValueOfObjCType: @encode(id) at: &filename]; + [aCoder decodeValueOfObjCType: @encode(id) at: &sourceLinks]; + [aCoder decodeValueOfObjCType: @encode(id) at: &destinationLinks]; + + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.areLinkOutlinesVisible = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.delegateVerifiesLinks = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.interactsWithUser = flag; + [aCoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; + _flags.isEdited = flag; + } + else + return nil; } - return self; } diff --git a/Source/NSNib.m b/Source/NSNib.m index b06e571fb..94ee6a8d6 100644 --- a/Source/NSNib.m +++ b/Source/NSNib.m @@ -208,7 +208,7 @@ // if([coder allowsKeyedCoding]) { - // Need to verify this key... + // TODO_NIB: Need to verify this key... ASSIGN(_nibData, [coder decodeObjectForKey: @"NSData"]); ASSIGN(_loader, [GSModelLoaderFactory modelLoaderForFileType: @"nib"]); } @@ -227,7 +227,7 @@ { if([coder allowsKeyedCoding]) { - // Need to verify this key... + // TODO_NIB: Need to verify this key... [coder encodeObject: _nibData forKey: @"NSData"]; } diff --git a/Source/NSParagraphStyle.m b/Source/NSParagraphStyle.m index 1544d2224..b08ce9bbd 100644 --- a/Source/NSParagraphStyle.m +++ b/Source/NSParagraphStyle.m @@ -314,100 +314,112 @@ static NSParagraphStyle *defaultStyle = nil; - (id) initWithCoder: (NSCoder*)aCoder { - unsigned count; - - [aCoder decodeValueOfObjCType: @encode(NSTextAlignment) at: &_alignment]; - [aCoder decodeValueOfObjCType: @encode(NSLineBreakMode) - at: &_lineBreakMode]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_firstLineHeadIndent]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_headIndent]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_lineSpacing]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_maximumLineHeight]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_minimumLineHeight]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_paragraphSpacing]; - [aCoder decodeValueOfObjCType: @encode(float) at: &_tailIndent]; - - /* - * Tab stops don't conform to NSCoding - so we do it the long way. - */ - [aCoder decodeValueOfObjCType: @encode(unsigned) at: &count]; - _tabStops = [[NSMutableArray alloc] initWithCapacity: count]; - if (count > 0) + if([aCoder allowsKeyedCoding]) { - float locations[count]; - NSTextTabType types[count]; - unsigned i; - - [aCoder decodeArrayOfObjCType: @encode(float) - count: count - at: locations]; - [aCoder decodeArrayOfObjCType: @encode(NSTextTabType) - count: count - at: types]; - for (i = 0; i < count; i++) + // TODO_NIB: Determine keys for NSParagraphStyle, if there are any. + } + else + { + unsigned count; + + [aCoder decodeValueOfObjCType: @encode(NSTextAlignment) at: &_alignment]; + [aCoder decodeValueOfObjCType: @encode(NSLineBreakMode) + at: &_lineBreakMode]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_firstLineHeadIndent]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_headIndent]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_lineSpacing]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_maximumLineHeight]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_minimumLineHeight]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_paragraphSpacing]; + [aCoder decodeValueOfObjCType: @encode(float) at: &_tailIndent]; + + /* + * Tab stops don't conform to NSCoding - so we do it the long way. + */ + [aCoder decodeValueOfObjCType: @encode(unsigned) at: &count]; + _tabStops = [[NSMutableArray alloc] initWithCapacity: count]; + if (count > 0) { - NSTextTab *tab; - - tab = [NSTextTab alloc]; - tab = [tab initWithType: types[i] location: locations[i]]; - [_tabStops addObject: tab]; - RELEASE (tab); + float locations[count]; + NSTextTabType types[count]; + unsigned i; + + [aCoder decodeArrayOfObjCType: @encode(float) + count: count + at: locations]; + [aCoder decodeArrayOfObjCType: @encode(NSTextTabType) + count: count + at: types]; + for (i = 0; i < count; i++) + { + NSTextTab *tab; + + tab = [NSTextTab alloc]; + tab = [tab initWithType: types[i] location: locations[i]]; + [_tabStops addObject: tab]; + RELEASE (tab); + } + } + + if ([aCoder versionForClassName: @"NSParagraphStyle"] >= 2) + { + [aCoder decodeValueOfObjCType: @encode(int) at: &_baseDirection]; } } - - if ([aCoder versionForClassName: @"NSParagraphStyle"] >= 2) - { - [aCoder decodeValueOfObjCType: @encode(int) at: &_baseDirection]; - } - return self; } - (void) encodeWithCoder: (NSCoder*)aCoder { - unsigned count; - - [aCoder encodeValueOfObjCType: @encode(NSTextAlignment) at: &_alignment]; - [aCoder encodeValueOfObjCType: @encode(NSLineBreakMode) - at: &_lineBreakMode]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_firstLineHeadIndent]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_headIndent]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_lineSpacing]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_maximumLineHeight]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_minimumLineHeight]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_paragraphSpacing]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_tailIndent]; - - /* - * Tab stops don't conform to NSCoding - so we do it the long way. - */ - count = [_tabStops count]; - [aCoder encodeValueOfObjCType: @encode(unsigned) at: &count]; - if (count > 0) + if([aCoder allowsKeyedCoding]) { - float locations[count]; - NSTextTabType types[count]; - unsigned i; - - for (i = 0; i < count; i++) - { - NSTextTab *tab = [_tabStops objectAtIndex: i]; - - locations[i] = [tab location]; - types[i] = [tab tabStopType]; - } - [aCoder encodeArrayOfObjCType: @encode(float) - count: count - at: locations]; - [aCoder encodeArrayOfObjCType: @encode(NSTextTabType) - count: count - at: types]; + // TODO_NIB: Determine keys for NSParagraphStyle, if there are any. + } + else + { + unsigned count; + + [aCoder encodeValueOfObjCType: @encode(NSTextAlignment) at: &_alignment]; + [aCoder encodeValueOfObjCType: @encode(NSLineBreakMode) + at: &_lineBreakMode]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_firstLineHeadIndent]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_headIndent]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_lineSpacing]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_maximumLineHeight]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_minimumLineHeight]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_paragraphSpacing]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_tailIndent]; + + /* + * Tab stops don't conform to NSCoding - so we do it the long way. + */ + count = [_tabStops count]; + [aCoder encodeValueOfObjCType: @encode(unsigned) at: &count]; + if (count > 0) + { + float locations[count]; + NSTextTabType types[count]; + unsigned i; + + for (i = 0; i < count; i++) + { + NSTextTab *tab = [_tabStops objectAtIndex: i]; + + locations[i] = [tab location]; + types[i] = [tab tabStopType]; + } + [aCoder encodeArrayOfObjCType: @encode(float) + count: count + at: locations]; + [aCoder encodeArrayOfObjCType: @encode(NSTextTabType) + count: count + at: types]; + } + + [aCoder encodeValueOfObjCType: @encode(int) at: &_baseDirection]; } - - [aCoder encodeValueOfObjCType: @encode(int) at: &_baseDirection]; } - - (BOOL) isEqual: (id)aother { NSParagraphStyle *other = aother; diff --git a/Source/NSSelection.m b/Source/NSSelection.m index 1ad5b43cc..19abf1046 100644 --- a/Source/NSSelection.m +++ b/Source/NSSelection.m @@ -211,23 +211,46 @@ typedef enum // - (void) encodeWithCoder: (NSCoder*)aCoder { - [aCoder encodeValueOfObjCType: @encode(BOOL) - at: &_isWellKnownSelection]; - [aCoder encodeValueOfObjCType: @encode(int) - at: &_selectionType]; - [aCoder encodeValueOfObjCType: @encode(id) - at: _descriptionData]; + if([aCoder allowsKeyedCoding]) + { + [aCoder encodeBool: _isWellKnownSelection + forKey: @"GSIsWellKnownSelection"]; + [aCoder encodeBool: _selectionType + forKey: @"GSSelectionType"]; + [aCoder encodeObject: _descriptionData + forKey: @"GSDescriptionData"]; + } + else + { + [aCoder encodeValueOfObjCType: @encode(BOOL) + at: &_isWellKnownSelection]; + [aCoder encodeValueOfObjCType: @encode(int) + at: &_selectionType]; + [aCoder encodeValueOfObjCType: @encode(id) + at: _descriptionData]; + } } - (id) initWithCoder: (NSCoder*)aDecoder { [super init]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) - at: &_isWellKnownSelection]; - [aDecoder decodeValueOfObjCType: @encode(int) - at: &_selectionType]; - [aDecoder decodeValueOfObjCType: @encode(id) - at: _descriptionData]; + if([aDecoder allowsKeyedCoding]) + { + _isWellKnownSelection = [aDecoder decodeBoolForKey: @"GSIsWellKnownSelection"]; + _selectionType = [aDecoder decodeIntForKey: @"GSSelectionType"]; + ASSIGN(_descriptionData, [aDecoder decodeObjectForKey: @"GSDescriptionData"]); + } + else + { + id obj; + [aDecoder decodeValueOfObjCType: @encode(BOOL) + at: &_isWellKnownSelection]; + [aDecoder decodeValueOfObjCType: @encode(int) + at: &_selectionType]; + [aDecoder decodeValueOfObjCType: @encode(id) + at: obj]; + ASSIGN(_descriptionData, obj); + } // if it's a well known selection then determine which one it is. if (_isWellKnownSelection) @@ -251,7 +274,7 @@ typedef enum break; } } - + return self; } diff --git a/Source/NSSound.m b/Source/NSSound.m index be5531a01..b441e7ebf 100644 --- a/Source/NSSound.m +++ b/Source/NSSound.m @@ -667,60 +667,73 @@ return NO; \ // - (void) encodeWithCoder: (NSCoder *)coder { - [coder encodeValueOfObjCType: @encode(BOOL) at: &_onlyReference]; - [coder encodeObject: _name]; - - if (_onlyReference == YES) + if([coder allowsKeyedCoding]) { - return; + // TODO_NIB: Determine keys for NSSound. } - - if (_uniqueIdentifier != nil) + else { - [coder encodeObject: _uniqueIdentifier]; + [coder encodeValueOfObjCType: @encode(BOOL) at: &_onlyReference]; + [coder encodeObject: _name]; + + if (_onlyReference == YES) + { + return; + } + + if (_uniqueIdentifier != nil) + { + [coder encodeObject: _uniqueIdentifier]; + } + + [coder encodeConditionalObject: _delegate]; + [coder encodeValueOfObjCType: @encode(long) at: &_dataLocation]; + [coder encodeValueOfObjCType: @encode(long) at: &_dataSize]; + [coder encodeValueOfObjCType: @encode(int) at: &_dataFormat]; + [coder encodeValueOfObjCType: @encode(float) at: &_samplingRate]; + [coder encodeValueOfObjCType: @encode(float) at: &_frameSize]; + [coder encodeValueOfObjCType: @encode(long) at: &_frameCount]; + [coder encodeValueOfObjCType: @encode(int) at: &_channelCount]; + + [coder encodeObject: _data]; } - - [coder encodeConditionalObject: _delegate]; - [coder encodeValueOfObjCType: @encode(long) at: &_dataLocation]; - [coder encodeValueOfObjCType: @encode(long) at: &_dataSize]; - [coder encodeValueOfObjCType: @encode(int) at: &_dataFormat]; - [coder encodeValueOfObjCType: @encode(float) at: &_samplingRate]; - [coder encodeValueOfObjCType: @encode(float) at: &_frameSize]; - [coder encodeValueOfObjCType: @encode(long) at: &_frameCount]; - [coder encodeValueOfObjCType: @encode(int) at: &_channelCount]; - - [coder encodeObject: _data]; } - (id) initWithCoder: (NSCoder*)decoder { - [decoder decodeValueOfObjCType: @encode(BOOL) at: &_onlyReference]; - - if (_onlyReference == YES) + if([decoder allowsKeyedCoding]) { - NSString *theName = [decoder decodeObject]; - - RELEASE (self); - self = RETAIN ([NSSound soundNamed: theName]); - [self setName: theName]; - } - else - { - _name = TEST_RETAIN ([decoder decodeObject]); - _uniqueIdentifier = TEST_RETAIN ([decoder decodeObject]); - [self setDelegate: [decoder decodeObject]]; - - [decoder decodeValueOfObjCType: @encode(long) at: &_dataLocation]; - [decoder decodeValueOfObjCType: @encode(long) at: &_dataSize]; - [decoder decodeValueOfObjCType: @encode(int) at: &_dataFormat]; - [decoder decodeValueOfObjCType: @encode(float) at: &_samplingRate]; - [decoder decodeValueOfObjCType: @encode(float) at: &_frameSize]; - [decoder decodeValueOfObjCType: @encode(long) at: &_frameCount]; - [decoder decodeValueOfObjCType: @encode(int) at: &_channelCount]; - - _data = RETAIN([decoder decodeObject]); + // TODO_NIB: Determine keys for NSSound. + } + else + { + [decoder decodeValueOfObjCType: @encode(BOOL) at: &_onlyReference]; + + if (_onlyReference == YES) + { + NSString *theName = [decoder decodeObject]; + + RELEASE (self); + self = RETAIN ([NSSound soundNamed: theName]); + [self setName: theName]; + } + else + { + _name = TEST_RETAIN ([decoder decodeObject]); + _uniqueIdentifier = TEST_RETAIN ([decoder decodeObject]); + [self setDelegate: [decoder decodeObject]]; + + [decoder decodeValueOfObjCType: @encode(long) at: &_dataLocation]; + [decoder decodeValueOfObjCType: @encode(long) at: &_dataSize]; + [decoder decodeValueOfObjCType: @encode(int) at: &_dataFormat]; + [decoder decodeValueOfObjCType: @encode(float) at: &_samplingRate]; + [decoder decodeValueOfObjCType: @encode(float) at: &_frameSize]; + [decoder decodeValueOfObjCType: @encode(long) at: &_frameCount]; + [decoder decodeValueOfObjCType: @encode(int) at: &_channelCount]; + + _data = RETAIN([decoder decodeObject]); + } } - return self; } diff --git a/Source/NSTextAttachment.m b/Source/NSTextAttachment.m index 5f390104a..2d09678fc 100644 --- a/Source/NSTextAttachment.m +++ b/Source/NSTextAttachment.m @@ -323,17 +323,31 @@ */ - (void) encodeWithCoder: (NSCoder*)aCoder { - [aCoder encodeObject: _fileWrapper]; - [aCoder encodeObject: _cell]; + if([aCoder allowsKeyedCoding]) + { + // TODO_NIB: Determine keys for NSTextAttachment. + } + else + { + [aCoder encodeObject: _fileWrapper]; + [aCoder encodeObject: _cell]; + } } - (id) initWithCoder: (NSCoder*)aDecoder { - [aDecoder decodeValueOfObjCType: @encode(id) at: &_fileWrapper]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_cell]; - - // Reconnect the cell, so the cell does not have to store the attachment - [_cell setAttachment: self]; + if([aDecoder allowsKeyedCoding]) + { + // TODO_NIB: Determine keys for NSTextAttachment. + } + else + { + [aDecoder decodeValueOfObjCType: @encode(id) at: &_fileWrapper]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &_cell]; + + // Reconnect the cell, so the cell does not have to store the attachment + [_cell setAttachment: self]; + } return self; }