Added keyed decoding.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18530 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2004-02-02 21:40:00 +00:00
parent 2c97e5fa28
commit afabdddd55
7 changed files with 171 additions and 61 deletions

View file

@ -1,3 +1,14 @@
2004-02-02 Fred Kiefer <FredKiefer@gmx.de>
* 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 <FredKiefer@gmx.de>
* Source/NSTextFieldCell.m (-setBackgroundColor:,

View file

@ -29,6 +29,7 @@
#include <Foundation/NSArray.h>
#include <Foundation/NSDebug.h>
#include <Foundation/NSException.h>
#include <Foundation/NSKeyedArchiver.h>
#include <Foundation/NSString.h>
#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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}