diff --git a/ChangeLog b/ChangeLog index 396232017..0799440cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-02-02 Fred Kiefer + + * Source/NSFont.m + Try to get at least some font on keyed decoding. + * Source/NSTextFieldCell.m + * Source/NSImageCell.m + * Source/NSImageView.m + * Source/NSBox.m + * Source/NSSplitView.m + Added keyed decoding. + 2004-02-01 Fred Kiefer * Source/NSTextFieldCell.m (-setBackgroundColor:, diff --git a/Source/NSBox.m b/Source/NSBox.m index 715d2ae48..db836e967 100644 --- a/Source/NSBox.m +++ b/Source/NSBox.m @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "AppKit/NSBox.h" @@ -407,33 +408,68 @@ - (id) initWithCoder: (NSCoder*)aDecoder { - [super initWithCoder: aDecoder]; + self = [super initWithCoder: aDecoder]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_cell]; - _offsets = [aDecoder decodeSize]; - [aDecoder decodeValueOfObjCType: @encode(NSBorderType) - at: &_border_type]; - [aDecoder decodeValueOfObjCType: @encode(NSTitlePosition) - at: &_title_position]; + if ([aDecoder allowsKeyedCoding]) + { + NSView *contentView = [aDecoder decodeObjectForKey: @"NSContentView"]; + NSCell *titleCell = [aDecoder decodeObjectForKey: @"NSTitleCell"]; - // The content view is our only sub_view - if ([_sub_views count] == 0) - { - - NSDebugLLog(@"NSBox", @"NSBox: decoding without content view\n"); - // No content view - _content_view = nil; - [self calcSizesAllowingNegative: NO]; - } - else - { - if ([_sub_views count] != 1) - { - NSLog (@"Warning: Encoded NSBox with more than one content view!"); + [self setContentView: contentView]; + ASSIGN(_cell, titleCell); + if ([aDecoder containsValueForKey: @"NSBoxType"]) + { + //int boxType = [aDecoder decodeIntForKey: @"NSBoxType"]; } - _content_view = [_sub_views objectAtIndex: 0]; - // The following also computes _title_rect and _border_rect. - [_content_view setFrame: [self calcSizesAllowingNegative: NO]]; + if ([aDecoder containsValueForKey: @"NSBorderType"]) + { + NSBorderType borderType = [aDecoder decodeIntForKey: @"NSBorderType"]; + + [self setBorderType: borderType]; + } + if ([aDecoder containsValueForKey: @"NSTitlePosition"]) + { + NSTitlePosition titlePosition = [aDecoder decodeIntForKey: + @"NSTitlePosition"]; + + [self setTitlePosition: titlePosition]; + } + if ([aDecoder containsValueForKey: @"NSTransparent"]) + { + //Bool transparent = [aDecoder decodeBoolForKey: @"NSTransparent"]; + } + if ([aDecoder containsValueForKey: @"NSOffsets"]) + { + [self setContentViewMargins: [aDecoder decodeSizeForKey: @"NSOffsets"]]; + } + } + else + { + [aDecoder decodeValueOfObjCType: @encode(id) at: &_cell]; + _offsets = [aDecoder decodeSize]; + [aDecoder decodeValueOfObjCType: @encode(NSBorderType) + at: &_border_type]; + [aDecoder decodeValueOfObjCType: @encode(NSTitlePosition) + at: &_title_position]; + + // The content view is our only sub_view + if ([_sub_views count] == 0) + { + NSDebugLLog(@"NSBox", @"NSBox: decoding without content view\n"); + // No content view + _content_view = nil; + [self calcSizesAllowingNegative: NO]; + } + else + { + if ([_sub_views count] != 1) + { + NSLog (@"Warning: Encoded NSBox with more than one content view!"); + } + _content_view = [_sub_views objectAtIndex: 0]; + // The following also computes _title_rect and _border_rect. + [_content_view setFrame: [self calcSizesAllowingNegative: NO]]; + } } return self; } diff --git a/Source/NSFont.m b/Source/NSFont.m index 2b1b0676a..b6cdec2db 100644 --- a/Source/NSFont.m +++ b/Source/NSFont.m @@ -986,11 +986,28 @@ static BOOL flip_hack; RELEASE(self); if ([aDecoder containsValueForKey: @"NSfFlags"]) { - //int flags = [aDecoder decodeIntForKey: @"NSfFlags"]; + int flags = [aDecoder decodeIntForKey: @"NSfFlags"]; // FIXME + if (flags == 16) + { + return [NSFont controlContentFontOfSize: size]; + } + else if (flags == 20) + { + return [NSFont labelFontOfSize: size]; + } + else if (flags == 22) + { + return [NSFont titleBarFontOfSize: size]; + } } self = [NSFont fontWithName: name size: size]; + if (self == nil) + { + self = [NSFont systemFontOfSize: size]; + } + return self; } else diff --git a/Source/NSImageCell.m b/Source/NSImageCell.m index fad10dd66..b43d1202b 100644 --- a/Source/NSImageCell.m +++ b/Source/NSImageCell.m @@ -374,12 +374,34 @@ scaleProportionally(NSSize imageSize, NSRect canvasRect) - (id) initWithCoder: (NSCoder *)aDecoder { - [super initWithCoder: aDecoder]; + self = [super initWithCoder: aDecoder]; - [aDecoder decodeValueOfObjCType: @encode(NSImageAlignment) at: &_imageAlignment]; - [aDecoder decodeValueOfObjCType: @encode(NSImageFrameStyle) at: &_frameStyle]; - [aDecoder decodeValueOfObjCType: @encode(NSImageScaling) at: &_imageScaling]; - _original_image_size = [aDecoder decodeSize]; + if ([aDecoder allowsKeyedCoding]) + { + if ([aDecoder containsValueForKey: @"NSAlign"]) + { + [self setImageAlignment: [aDecoder decodeIntForKey: @"NSAlign"]]; + } + if ([aDecoder containsValueForKey: @"NSScale"]) + { + [self setImageScaling: [aDecoder decodeIntForKey: @"NSScale"]]; + } + if ([aDecoder containsValueForKey: @"NSStyle"]) + { + [self setImageFrameStyle: [aDecoder decodeIntForKey: @"NSStyle"]]; + } + if ([aDecoder containsValueForKey: @"NSAnimates"]) + { + //BOOL animates = [aDecoder decodeBoolForKey: @"NSAnimates"]; + } + } + else + { + [aDecoder decodeValueOfObjCType: @encode(NSImageAlignment) at: &_imageAlignment]; + [aDecoder decodeValueOfObjCType: @encode(NSImageFrameStyle) at: &_frameStyle]; + [aDecoder decodeValueOfObjCType: @encode(NSImageScaling) at: &_imageScaling]; + _original_image_size = [aDecoder decodeSize]; + } return self; } diff --git a/Source/NSImageView.m b/Source/NSImageView.m index cf8ad9e12..a26262917 100644 --- a/Source/NSImageView.m +++ b/Source/NSImageView.m @@ -276,10 +276,23 @@ static Class imageCellClass; - (id) initWithCoder: (NSCoder *)aDecoder { self = [super initWithCoder: aDecoder]; - if ([aDecoder versionForClassName: @"NSImageView"] >= 2) + + if ([aDecoder allowsKeyedCoding]) { - _target = [aDecoder decodeObject]; - [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action]; + //NSArray *dragType = [aDecoder decodeObjectForKey: @"NSDragTypes"]; + + if ([aDecoder containsValueForKey: @"NSEditable"]) + { + [self setEditable: [aDecoder decodeBoolForKey: @"NSEditable"]]; + } + } + else + { + if ([aDecoder versionForClassName: @"NSImageView"] >= 2) + { + _target = [aDecoder decodeObject]; + [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action]; + } } return self; } diff --git a/Source/NSSplitView.m b/Source/NSSplitView.m index eb519aeef..3cbedc73d 100644 --- a/Source/NSSplitView.m +++ b/Source/NSSplitView.m @@ -898,33 +898,35 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect) - (id) initWithCoder: (NSCoder *)aDecoder { self = [super initWithCoder: aDecoder]; + + if ([aDecoder allowsKeyedCoding]) + { + if ([aDecoder containsValueForKey: @"NSIsVertical"]) + { + [self setVertical: [aDecoder decodeBoolForKey: @"NSIsVertical"]]; + } + } + else + { + // Decode objects that we don't retain. + [self setDelegate: [aDecoder decodeObject]]; - /* - * Decode objects that we don't retain. - */ - [self setDelegate: [aDecoder decodeObject]]; + // Decode objects that we do retain. + [aDecoder decodeValueOfObjCType: @encode(id) at: &_dimpleImage]; + if (_dimpleImage == nil) + ASSIGN(_dimpleImage, [NSImage imageNamed: @"common_Dimple.tiff"]); - /* - * Decode objects that we do retain. - */ - [aDecoder decodeValueOfObjCType: @encode(id) at: &_dimpleImage]; - if (_dimpleImage == nil) - ASSIGN(_dimpleImage, [NSImage imageNamed: @"common_Dimple.tiff"]); + [aDecoder decodeValueOfObjCType: @encode(id) at: &_backgroundColor]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &_dividerColor]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_backgroundColor]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_dividerColor]; + // Decode non-object data. + [aDecoder decodeValueOfObjCType: @encode(int) at: &_draggedBarWidth]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isVertical]; - /* - * Decode non-object data. - */ - [aDecoder decodeValueOfObjCType: @encode(int) at: &_draggedBarWidth]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isVertical]; + _dividerWidth = [self dividerThickness]; + _never_displayed_before = YES; + } - /* - * - */ - _dividerWidth = [self dividerThickness]; - _never_displayed_before = YES; return self; } diff --git a/Source/NSTextFieldCell.m b/Source/NSTextFieldCell.m index c3915755c..50770cc14 100644 --- a/Source/NSTextFieldCell.m +++ b/Source/NSTextFieldCell.m @@ -198,14 +198,23 @@ static NSColor *txtCol; - (id) initWithCoder: (NSCoder*)aDecoder { - BOOL tmp; [super initWithCoder: aDecoder]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_background_color]; - [aDecoder decodeValueOfObjCType: @encode(id) at: &_text_color]; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp]; - _textfieldcell_draws_background = tmp; - _textfieldcell_is_opaque = [self _isOpaque]; + if ([aDecoder allowsKeyedCoding]) + { + [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBackgroundColor"]]; + [self setTextColor: [aDecoder decodeObjectForKey: @"NSTextColor"]]; + } + else + { + BOOL tmp; + + [aDecoder decodeValueOfObjCType: @encode(id) at: &_background_color]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &_text_color]; + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp]; + _textfieldcell_draws_background = tmp; + _textfieldcell_is_opaque = [self _isOpaque]; + } return self; }