diff --git a/ChangeLog b/ChangeLog index 02b1ce4a6..35338812b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-10-08 Fred Kiefer + + * Source/NSFormCell.m: (-initWithCoder:): + * Source/NSMatrix.m: (-initWithCoder:): Implemented keyed decoding. + * Source/NSColor.m: (-initWithCoder:): Corrected handling of alpha + values (use 1 instead of 0) + * Source/NSCell.m: (-initWithCoder:): Added some more flag + handling and rearranged code. + 2004-10-08 09:17 Chad Hardin * Printing/GSLPR/GSLPRPageLayout.m: Fixed a #define diff --git a/Source/NSCell.m b/Source/NSCell.m index 790202b9a..458e68e9f 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -2006,7 +2006,8 @@ static NSColor *shadowCol; if ([aDecoder allowsKeyedCoding]) { NSString *contents = [aDecoder decodeObjectForKey: @"NSContents"]; - NSFont *support = [aDecoder decodeObjectForKey: @"NSSupport"]; + + self = [self initTextCell: contents]; if ([aDecoder containsValueForKey: @"NSCellFlags"]) { @@ -2022,6 +2023,10 @@ static NSColor *shadowCol; [self setSelectable: ((cFlags & 0x200001) == 0x200001)]; [self setBezeled: ((cFlags & 0x400000) == 0x400000)]; [self setBordered: ((cFlags & 0x800000) == 0x800000)]; + if ((cFlags & 0x4000000) == 0x4000000) + { + [self setType: NSTextCellType]; + } [self setEditable: ((cFlags & 0x10000000) == 0x10000000)]; // This bit flag is the other way around! [self setEnabled: ((cFlags & 0x20000000) != 0x20000000)]; @@ -2036,13 +2041,39 @@ static NSColor *shadowCol; cFlags2 = [aDecoder decodeIntForKey: @"NSCellFlags2"]; [self setAllowsMixedState: ((cFlags2 & 0x1000000) == 0x1000000)]; [self setRefusesFirstResponder: ((cFlags2 & 0x2000000) == 0x2000000)]; + if ((cFlags2 & 0x4000000) == 0x4000000) + { + [self setAlignment: NSRightTextAlignment]; + } + if ((cFlags2 & 0x8000000) == 0x8000000) + { + [self setAlignment: NSCenterTextAlignment]; + } + if ((cFlags2 & 0xC000000) == 0xC000000) + { + [self setAlignment: NSJustifiedTextAlignment]; + } + if ((cFlags2 & 0x10000000) == 0x10000000) + { + [self setAlignment: NSNaturalTextAlignment]; + } + [self setImportsGraphics: ((cFlags2 & 0x20000000) == 0x20000000)]; [self setAllowsEditingTextAttributes: ((cFlags2 & 0x40000000) == 0x40000000)]; // FIXME } + if ([aDecoder containsValueForKey: @"NSSupport"]) + { + NSFont *support = [aDecoder decodeObjectForKey: @"NSSupport"]; - self = [self initTextCell: contents]; - [self setFont: support]; + [self setFont: support]; + } + if ([aDecoder containsValueForKey: @"NSFormatter"]) + { + NSFormatter *formatter = [aDecoder decodeObjectForKey: @"NSFormatter"]; + + [self setFormatter: formatter]; + } } else { diff --git a/Source/NSColor.m b/Source/NSColor.m index 3c6e78004..4b889c315 100644 --- a/Source/NSColor.m +++ b/Source/NSColor.m @@ -1056,7 +1056,7 @@ systemColorWithName(NSString *name) float red = 0.0; float green = 0.0; float blue = 0.0; - float alpha = 0.0; + float alpha = 1.0; NSString *str; NSScanner *scanner; @@ -1069,8 +1069,10 @@ systemColorWithName(NSString *name) [scanner scanFloat: &red]; [scanner scanFloat: &green]; [scanner scanFloat: &blue]; + RELEASE(scanner); + RELEASE(str); } - + self = [NSColor colorWithCalibratedRed: red green: green blue: blue @@ -1081,7 +1083,7 @@ systemColorWithName(NSString *name) unsigned length; const uint8_t *data; float white = 0.0; - float alpha = 0.0; + float alpha = 1.0; NSString *str; NSScanner *scanner; @@ -1092,6 +1094,8 @@ systemColorWithName(NSString *name) str = [[NSString alloc] initWithCString: data length: length]; scanner = [[NSScanner alloc] initWithString: str]; [scanner scanFloat: &white]; + RELEASE(scanner); + RELEASE(str); } self = [NSColor colorWithDeviceWhite: white diff --git a/Source/NSFormCell.m b/Source/NSFormCell.m index e6c1df0cc..cb5ffbf16 100644 --- a/Source/NSFormCell.m +++ b/Source/NSFormCell.m @@ -368,12 +368,24 @@ static NSColor *shadowCol; BOOL tmp; [super initWithCoder: aDecoder]; - - [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp]; - _formcell_auto_title_width = tmp; - [aDecoder decodeValueOfObjCType: @encode(float) at: &_displayedTitleWidth]; - [aDecoder decodeValueOfObjCType: @encode(id) - at: &_titleCell]; + if ([aDecoder allowsKeyedCoding]) + { + if ([aDecoder containsValueForKey: @"NSTitleWidth"]) + { + [self setTitleWidth: [aDecoder decodeFloatForKey: @"NSTitleWidth"]]; + } + if ([aDecoder containsValueForKey: @"NSTitleCell"]) + { + ASSIGN(_titleCell, [aDecoder decodeObjectForKey: @"NSTitleCell"]); + } + } + else + { + [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp]; + _formcell_auto_title_width = tmp; + [aDecoder decodeValueOfObjCType: @encode(float) at: &_displayedTitleWidth]; + [aDecoder decodeValueOfObjCType: @encode(id) at: &_titleCell]; + } return self; } diff --git a/Source/NSMatrix.m b/Source/NSMatrix.m index 5a3aada9d..209e3b7bf 100644 --- a/Source/NSMatrix.m +++ b/Source/NSMatrix.m @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -2477,77 +2478,164 @@ static SEL getSel; [super initWithCoder: aDecoder]; - _myZone = [self zone]; - [aDecoder decodeValueOfObjCType: @encode (int) at: &_mode]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_allowsEmptySelection]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_selectionByRect]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_autosizesCells]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_autoscroll]; - _cellSize = [aDecoder decodeSize]; - _intercell = [aDecoder decodeSize]; - [aDecoder decodeValueOfObjCType: @encode (id) at: &_backgroundColor]; - [aDecoder decodeValueOfObjCType: @encode (id) at: &_cellBackgroundColor]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_drawsBackground]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_drawsCellBackground]; - - class = NSClassFromString ((NSString *)[aDecoder decodeObject]); - if (class != Nil) + if ([aDecoder allowsKeyedCoding]) { - [self setCellClass: class]; - } + if ([aDecoder containsValueForKey: @"NSBackgroundColor"]) + { + [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBackgroundColor"]]; + } + if ([aDecoder containsValueForKey: @"NSCellBackgroundColor"]) + { + [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSCellBackgroundColor"]]; + } + if ([aDecoder containsValueForKey: @"NSProtoCell"]) + { + [self setPrototype: [aDecoder decodeObjectForKey: @"NSProtoCell"]]; + } + if ([aDecoder containsValueForKey: @"NSCellClass"]) + { + class = NSClassFromString((NSString *)[aDecoder decodeObjectForKey: @"NSCellClass"]); + if (class != Nil) + { + [self setCellClass: class]; + } + } + if ([aDecoder containsValueForKey: @"NSCellSize"]) + { + [self setCellSize: [aDecoder decodeSizeForKey: @"NSCellSize"]]; + } + if ([aDecoder containsValueForKey: @"NSIntercellSpacing"]) + { + [self setIntercellSpacing: [aDecoder decodeSizeForKey: @"NSIntercellSpacing"]]; + } + if ([aDecoder containsValueForKey: @"NSMatrixFlags"]) + { + int mFlags; - cell = [aDecoder decodeObject]; - if (cell != nil) - { - [self setPrototype: cell]; - } + mFlags = [aDecoder decodeIntForKey: @"NSMatrixFlags"]; + // FIXME + } + if ([aDecoder containsValueForKey: @"NSNumCols"]) + { + columns = [aDecoder decodeIntForKey: @"NSNumCols"]; + } + if ([aDecoder containsValueForKey: @"NSNumRows"]) + { + rows = [aDecoder decodeIntForKey: @"NSNumRows"]; + } - if (_cellPrototype == nil) - { - [self setCellClass: [isa cellClass]]; - } + array = [aDecoder decodeObjectForKey: @"NSCells"]; + [self renewRows: rows columns: columns]; + count = [array count]; + if (count != rows * columns) + { + NSLog (@"Trying to decode an invalid NSMatrix: cell number does not fit matrix dimension"); + // Quick fix to do what we can + if (count > rows * columns) + { + count = rows * columns; + } + } - [aDecoder decodeValueOfObjCType: @encode (int) at: &rows]; - [aDecoder decodeValueOfObjCType: @encode (int) at: &columns]; - /* NB: This works without changes for NSForm */ - array = [aDecoder decodeObject]; - [self renewRows: rows columns: columns]; - count = [array count]; - if (count != rows * columns) - { - NSLog (@"Trying to decode an invalid NSMatrix: cell number does not fit matrix dimension"); - // Quick fix to do what we can - if (count > rows * columns) - { - count = rows * columns; + for (i = 0; i < count; i++) + { + int row, column; + cell = [array objectAtIndex: i]; + + row = i / columns; + column = i % columns; + + [self putCell:cell atRow: row column: column]; + if ([cell state]) + { + [self selectCellAtRow: row column: column]; + } + } + + if ([aDecoder containsValueForKey: @"NSSelectedCol"]) + { + _selectedColumn = [aDecoder decodeIntForKey: @"NSSelectedCol"]; + } + if ([aDecoder containsValueForKey: @"NSSelectedRow"]) + { + _selectedRow = [aDecoder decodeIntForKey: @"NSSelectedRow"]; } } - - _selectedRow = _selectedColumn = 0; - - for (i = 0; i < count; i++) + else { - int row, column; - cell = [array objectAtIndex: i]; - - row = i / columns; - column = i % columns; + _myZone = [self zone]; + [aDecoder decodeValueOfObjCType: @encode (int) at: &_mode]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_allowsEmptySelection]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_selectionByRect]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_autosizesCells]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_autoscroll]; + _cellSize = [aDecoder decodeSize]; + _intercell = [aDecoder decodeSize]; + [aDecoder decodeValueOfObjCType: @encode (id) at: &_backgroundColor]; + [aDecoder decodeValueOfObjCType: @encode (id) at: &_cellBackgroundColor]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_drawsBackground]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_drawsCellBackground]; - [self putCell:cell atRow: row column: column]; - if ([cell state]) - { - [self selectCellAtRow: row column: column]; - } - } + class = NSClassFromString ((NSString *)[aDecoder decodeObject]); + if (class != Nil) + { + [self setCellClass: class]; + } + + cell = [aDecoder decodeObject]; + if (cell != nil) + { + [self setPrototype: cell]; + } + + if (_cellPrototype == nil) + { + [self setCellClass: [isa cellClass]]; + } + + [aDecoder decodeValueOfObjCType: @encode (int) at: &rows]; + [aDecoder decodeValueOfObjCType: @encode (int) at: &columns]; - [aDecoder decodeValueOfObjCType: @encode (id) at: &_delegate]; - [aDecoder decodeValueOfObjCType: @encode (id) at: &_target]; - [aDecoder decodeValueOfObjCType: @encode (SEL) at: &_action]; - [aDecoder decodeValueOfObjCType: @encode (SEL) at: &_doubleAction]; - [aDecoder decodeValueOfObjCType: @encode (SEL) at: &_errorAction]; - [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_tabKeyTraversesCells]; - [self setKeyCell: [aDecoder decodeObject]]; + /* NB: This works without changes for NSForm */ + array = [aDecoder decodeObject]; + [self renewRows: rows columns: columns]; + count = [array count]; + if (count != rows * columns) + { + NSLog (@"Trying to decode an invalid NSMatrix: cell number does not fit matrix dimension"); + // Quick fix to do what we can + if (count > rows * columns) + { + count = rows * columns; + } + } + + _selectedRow = _selectedColumn = 0; + + for (i = 0; i < count; i++) + { + int row, column; + cell = [array objectAtIndex: i]; + + row = i / columns; + column = i % columns; + + [self putCell:cell atRow: row column: column]; + if ([cell state]) + { + [self selectCellAtRow: row column: column]; + } + } + + [aDecoder decodeValueOfObjCType: @encode (id) at: &_delegate]; + [aDecoder decodeValueOfObjCType: @encode (id) at: &_target]; + [aDecoder decodeValueOfObjCType: @encode (SEL) at: &_action]; + [aDecoder decodeValueOfObjCType: @encode (SEL) at: &_doubleAction]; + [aDecoder decodeValueOfObjCType: @encode (SEL) at: &_errorAction]; + [aDecoder decodeValueOfObjCType: @encode (BOOL) at: &_tabKeyTraversesCells]; + [self setKeyCell: [aDecoder decodeObject]]; + } return self; }