From d24ee43d13655432b28db5cf9cac486a9bf9ae78 Mon Sep 17 00:00:00 2001 From: gcasa Date: Sat, 19 Aug 2006 14:34:52 +0000 Subject: [PATCH] * Source/NSBrowserCell.m: Improved encoding and decoding in encodeWithCoder: and initWithCoder: * Source/NSBrowser.m: Improved encoding and decoding in encodeWithCoder: and initWithCoder: * Source/NSScrollView.m: Improved encoding and decoding in encodeWithCoder: and initWithCoder: git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23315 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 ++ Source/NSBrowser.m | 185 +++++++++++++++++++++++++---------------- Source/NSBrowserCell.m | 22 +++-- Source/NSScrollView.m | 2 + 4 files changed, 137 insertions(+), 81 deletions(-) diff --git a/ChangeLog b/ChangeLog index 783e729a9..707fd33a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-08-19 10:33-EDT Gregory John Casamento + + * Source/NSBrowserCell.m: Improved encoding and decoding in + encodeWithCoder: and initWithCoder: + * Source/NSBrowser.m: Improved encoding and decoding in + encodeWithCoder: and initWithCoder: + * Source/NSScrollView.m: Improved encoding and decoding in + encodeWithCoder: and initWithCoder: + 2006-08-17 00:54-EDT Gregory John Casamento * Source/NSButtonCell.m: Improvements in both initWithCoder: and diff --git a/Source/NSBrowser.m b/Source/NSBrowser.m index 3818b2f8b..8f78e22e3 100644 --- a/Source/NSBrowser.m +++ b/Source/NSBrowser.m @@ -152,30 +152,43 @@ static NSTextFieldCell *titleCell; - (void) encodeWithCoder: (NSCoder *)aCoder { - int dummy = 0; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded]; - [aCoder encodeObject: _columnScrollView]; - [aCoder encodeObject: _columnMatrix]; - [aCoder encodeValueOfObjCType: @encode(int) at: &dummy]; - [aCoder encodeObject: _columnTitle]; + if([aCoder allowsKeyedCoding]) + { + } + else + { + int dummy = 0; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded]; + [aCoder encodeObject: _columnScrollView]; + [aCoder encodeObject: _columnMatrix]; + [aCoder encodeValueOfObjCType: @encode(int) at: &dummy]; + [aCoder encodeObject: _columnTitle]; + } } - + - (id) initWithCoder: (NSCoder *)aDecoder { - int dummy = 0; + if([aDecoder allowsKeyedCoding]) + { + + } + else + { + int dummy = 0; - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isLoaded]; - _columnScrollView = [aDecoder decodeObject]; - if (_columnScrollView) - RETAIN(_columnScrollView); - _columnMatrix = [aDecoder decodeObject]; - if (_columnMatrix) - RETAIN(_columnMatrix); - [aDecoder decodeValueOfObjCType: @encode(int) at: &dummy]; - _columnTitle = [aDecoder decodeObject]; - if (_columnTitle) - RETAIN(_columnTitle); + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isLoaded]; + _columnScrollView = [aDecoder decodeObject]; + if (_columnScrollView) + RETAIN(_columnScrollView); + _columnMatrix = [aDecoder decodeObject]; + if (_columnMatrix) + RETAIN(_columnMatrix); + [aDecoder decodeValueOfObjCType: @encode(int) at: &dummy]; + _columnTitle = [aDecoder decodeObject]; + if (_columnTitle) + RETAIN(_columnTitle); + } return self; } @@ -2488,51 +2501,77 @@ static NSTextFieldCell *titleCell; - (void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; + if([aCoder allowsKeyedCoding]) + { + [aCoder encodeObject: _browserCellPrototype forKey: @"NSCellPrototype"]; + [aCoder encodeObject: [self _getTitleOfColumn: 0] forKey: @"NSFirstColumnTitle"]; + [aCoder encodeObject: _pathSeparator forKey: @"NSPathSeparator"]; - // Here to keep compatibility with old version - [aCoder encodeObject: nil]; - [aCoder encodeObject:_browserCellPrototype]; - [aCoder encodeObject: NSStringFromClass (_browserMatrixClass)]; + long flags = 0; + flags |= [self hasHorizontalScroller] ? 0x10000 : 0; + flags |= ([self allowsEmptySelection] == NO) ? 0x20000 : 0; + flags |= [self sendsActionOnArrowKeys] ? 0x40000 : 0; + flags |= [self acceptsArrowKeys] ? 0x100000 : 0; + flags |= [self separatesColumns] ? 0x4000000 : 0; + flags |= [self takesTitleFromPreviousColumn] ? 0x8000000 : 0; + flags |= [self isTitled] ? 0x10000000 : 0; + flags |= [self reusesColumns] ? 0x20000000 : 0; + flags |= [self allowsBranchSelection] ? 0x40000000 : 0; + flags |= [self allowsMultipleSelection] ? 0x80000000 : 0; + [aCoder encodeInt: flags forKey: @"NSBrFlags"]; - [aCoder encodeObject:_pathSeparator]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsBranchSelection]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection]; - [aCoder encodeValueOfObjCType: @encode(int) at: &_maxVisibleColumns]; - [aCoder encodeValueOfObjCType: @encode(float) at: &_minColumnWidth]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_reusesColumns]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_separatesColumns]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_takesTitleFromPreviousColumn]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isTitled]; - - - [aCoder encodeObject:_horizontalScroller]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHorizontalScroller]; - [aCoder encodeRect: _scrollerRect]; - [aCoder encodeSize: _columnSize]; - - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_acceptsArrowKeys]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_sendsActionOnArrowKeys]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_acceptsAlphaNumericalKeys]; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_sendsActionOnAlphaNumericalKeys]; - - [aCoder encodeConditionalObject:_browserDelegate]; - - [aCoder encodeValueOfObjCType: @encode(SEL) at: &_doubleAction]; - [aCoder encodeConditionalObject: _target]; - [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; - - [aCoder encodeObject: _browserColumns]; - - // Just encode the number of columns and the first visible - // and rebuild the browser columns on the decoding side - { - int colCount = [_browserColumns count]; - [aCoder encodeValueOfObjCType: @encode(int) at: &colCount]; - [aCoder encodeValueOfObjCType: @encode(int) at: &_firstVisibleColumn]; - } + [aCoder encodeInt: _maxVisibleColumns forKey: @"NSNumberOfVisibleColumns"]; + [aCoder encodeFloat: _minColumnWidth forKey: @"NSMinColumnWidth"]; + //[aCoder encodeInt: columnResizingType forKey: @"NSColumnResizingType"]]; + //[aCoder encodeInt: prefWidth forKey: @"NSPreferedColumnWidth"]; + } + else + { + // Here to keep compatibility with old version + [aCoder encodeObject: nil]; + [aCoder encodeObject:_browserCellPrototype]; + [aCoder encodeObject: NSStringFromClass (_browserMatrixClass)]; + + [aCoder encodeObject:_pathSeparator]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsBranchSelection]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsMultipleSelection]; + [aCoder encodeValueOfObjCType: @encode(int) at: &_maxVisibleColumns]; + [aCoder encodeValueOfObjCType: @encode(float) at: &_minColumnWidth]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_reusesColumns]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_separatesColumns]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_takesTitleFromPreviousColumn]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isTitled]; + + + [aCoder encodeObject:_horizontalScroller]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_hasHorizontalScroller]; + [aCoder encodeRect: _scrollerRect]; + [aCoder encodeSize: _columnSize]; + + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_acceptsArrowKeys]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_sendsActionOnArrowKeys]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_acceptsAlphaNumericalKeys]; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_sendsActionOnAlphaNumericalKeys]; + + [aCoder encodeConditionalObject:_browserDelegate]; + + [aCoder encodeValueOfObjCType: @encode(SEL) at: &_doubleAction]; + [aCoder encodeConditionalObject: _target]; + [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; + + [aCoder encodeObject: _browserColumns]; + + // Just encode the number of columns and the first visible + // and rebuild the browser columns on the decoding side + { + int colCount = [_browserColumns count]; + [aCoder encodeValueOfObjCType: @encode(int) at: &colCount]; + [aCoder encodeValueOfObjCType: @encode(int) at: &_firstVisibleColumn]; + } + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -2544,7 +2583,7 @@ static NSTextFieldCell *titleCell; NSCell *proto = [aDecoder decodeObjectForKey: @"NSCellPrototype"]; NSString *title = [aDecoder decodeObjectForKey: @"NSFirstColumnTitle"]; NSString *sep = [aDecoder decodeObjectForKey: @"NSPathSeparator"]; - int flags; + long flags; // start // NSSize bs; @@ -2615,16 +2654,16 @@ static NSTextFieldCell *titleCell; { flags = [aDecoder decodeIntForKey: @"NSBrFlags"]; - [self setHasHorizontalScroller: (flags & 0x10000)]; - [self setAllowsEmptySelection: !(flags & 0x20000)]; - [self setSendsActionOnArrowKeys: (flags & 0x40000)]; - [self setAcceptsArrowKeys: (flags & 0x100000)]; - [self setSeparatesColumns: (flags & 0x4000000)]; - [self setTakesTitleFromPreviousColumn: (flags & 0x8000000)]; - [self setTitled: (flags & 0x10000000)]; - [self setReusesColumns: (flags & 0x20000000)]; - [self setAllowsBranchSelection: (flags & 0x40000000)]; - [self setAllowsMultipleSelection: (flags & 0x80000000)]; + [self setHasHorizontalScroller: ((flags & 0x10000) == 0x10000)]; + [self setAllowsEmptySelection: !((flags & 0x20000) == 0x20000)]; + [self setSendsActionOnArrowKeys: ((flags & 0x40000) == 0x40000)]; + [self setAcceptsArrowKeys: ((flags & 0x100000) == 0x100000)]; + [self setSeparatesColumns: ((flags & 0x4000000) == 0x4000000)]; + [self setTakesTitleFromPreviousColumn: ((flags & 0x8000000) == 0x8000000)]; + [self setTitled: ((flags & 0x10000000) == 0x10000000)]; + [self setReusesColumns: ((flags & 0x20000000) == 0x20000000)]; + [self setAllowsBranchSelection: ((flags & 0x40000000) == 0x40000000)]; + [self setAllowsMultipleSelection: ((flags & 0x80000000) == 0x80000000)]; } if ([aDecoder containsValueForKey: @"NSNumberOfVisibleColumns"]) diff --git a/Source/NSBrowserCell.m b/Source/NSBrowserCell.m index c099623c3..1d9853a1c 100644 --- a/Source/NSBrowserCell.m +++ b/Source/NSBrowserCell.m @@ -338,14 +338,20 @@ static NSFont *_leafFont; */ - (void) encodeWithCoder: (NSCoder*)aCoder { - BOOL tmp; [super encodeWithCoder: aCoder]; - - tmp = _browsercell_is_leaf; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp]; - tmp = _browsercell_is_loaded; - [aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp]; - [aCoder encodeObject: _alternateImage]; + if([aCoder allowsKeyedCoding]) + { + // simply encodes prescence... + } + else + { + BOOL tmp; + tmp = _browsercell_is_leaf; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp]; + tmp = _browsercell_is_loaded; + [aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp]; + [aCoder encodeObject: _alternateImage]; + } } - (id) initWithCoder: (NSCoder*)aDecoder @@ -354,7 +360,7 @@ static NSFont *_leafFont; if ([aDecoder allowsKeyedCoding]) { - // Nothing special + // Nothing to decode... } else { diff --git a/Source/NSScrollView.m b/Source/NSScrollView.m index 4366cfbc8..a541ebcb4 100644 --- a/Source/NSScrollView.m +++ b/Source/NSScrollView.m @@ -1236,6 +1236,8 @@ static float scrollerWidth; scrollViewFlags.hasVScroller = _hasVertScroller; scrollViewFlags.hasHScroller = _hasHorizScroller; scrollViewFlags.border = _borderType; + scrollViewFlags.__unused4 = 0; + scrollViewFlags.__unused0 = 0; memcpy((void *)&flags, (void *)&scrollViewFlags,sizeof(unsigned long)); [aCoder encodeInt: flags forKey: @"NSsFlags"];