Correction for window size in -[NSWindowTemplate nibInstantiate]. Implemented encoding in encodeWithCoder: for some classes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23207 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gcasa 2006-08-06 04:32:16 +00:00
parent 1b1a55d80b
commit 78abe49764
12 changed files with 394 additions and 165 deletions

View file

@ -1,3 +1,18 @@
2006-08-06 00:30-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GSNibCompatibility.m: Correction in nibInstantiate for
window frame.
* Source/NSActionCell.m
* Source/NSButtonCell.m
* Source/NSCell.m
* Source/NSComboBoxCell.m
* Source/NSControl.m
* Source/NSMatrix.m
* Source/NSTableView.m
* Source/NSTextContainer.m
* Source/NSTextStorage.m
* Source/NSTextView.m: Encoding in encodeWithCoder:.
2006-08-05 09:08-EDT Gregory John Casamento <greg_casamento@yahoo.com> 2006-08-05 09:08-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSMenu.m: encodeWithCoder: encode items and title of * Source/NSMenu.m: encodeWithCoder: encode items and title of

View file

@ -283,8 +283,7 @@ static BOOL _isInInterfaceBuilder = NO;
[_view _fixSubviews]; [_view _fixSubviews];
// resize the window... // resize the window...
[_realObject setFrame: [NSWindow frameRectForContentRect: [self windowRect] [_realObject setFrame: [self windowRect]
styleMask: [self windowStyle]]
display: NO]; display: NO];
// swap out any views which need to be swapped... // swap out any views which need to be swapped...

View file

@ -285,12 +285,21 @@ static Class controlClass;
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if([aCoder allowsKeyedCoding])
{
[aCoder encodeInt: [self tag] forKey: @"NSTag"];
[aCoder encodeObject: [self target] forKey: @"NSTarget"];
[aCoder encodeObject: NSStringFromSelector([self action]) forKey: @"NSAction"];
}
else
{
[aCoder encodeValueOfObjCType: @encode(int) at: &_tag]; [aCoder encodeValueOfObjCType: @encode(int) at: &_tag];
[aCoder encodeConditionalObject: _target]; [aCoder encodeConditionalObject: _target];
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action]; [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
// This is only encoded for backward compatibility and won't be decoded. // This is only encoded for backward compatibility and won't be decoded.
[aCoder encodeConditionalObject: nil]; [aCoder encodeConditionalObject: nil];
} }
}
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {

View file

@ -1443,9 +1443,36 @@ typedef struct _GSButtonCellFlags
{ {
BOOL tmp; BOOL tmp;
// FIXME: Add new ivars
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if([aCoder allowsKeyedCoding])
{
GSButtonCellFlags buttonCellFlags;
unsigned int bFlags = 0;
unsigned int bFlags2 = 0;
[aCoder encodeObject: [self keyEquivalent] forKey: @"NSKeyEquivalent"];
[aCoder encodeObject: [self image] forKey: @"NSNormalImage"];
[aCoder encodeObject: [self alternateTitle] forKey: @"NSAlternateContents"];
// encode button flags...
buttonCellFlags.isTransparent = [self isTransparent];
buttonCellFlags.isBordered = [self isBordered];
buttonCellFlags.highlightByBackground = (_highlightsByMask & NSChangeBackgroundCellMask);
buttonCellFlags.highlightByContents = (_highlightsByMask & NSContentsCellMask);
buttonCellFlags.isPushin = (_highlightsByMask & NSPushInCellMask);
buttonCellFlags.changeBackground = (_showAltStateMask & NSChangeBackgroundCellMask);
buttonCellFlags.changeContents = (_showAltStateMask & NSContentsCellMask);
memcpy((void *)&bFlags, (void *)&buttonCellFlags,sizeof(unsigned int));
[aCoder encodeInt: bFlags forKey: @"NSButtonFlags"];
// style and border.
bFlags2 != [self showsBorderOnlyWhileMouseInside] ? 0x8 : 0;
bFlags2 |= [self bezelStyle];
[aCoder encodeInt: bFlags2 forKey: @"NSButtonFlags2"];
}
else
{
// FIXME: Add new ivars
[aCoder encodeObject: _keyEquivalent]; [aCoder encodeObject: _keyEquivalent];
[aCoder encodeObject: _keyEquivalentFont]; [aCoder encodeObject: _keyEquivalentFont];
[aCoder encodeObject: _altContents]; [aCoder encodeObject: _altContents];
@ -1461,6 +1488,7 @@ typedef struct _GSButtonCellFlags
at: &_showAltStateMask]; at: &_showAltStateMask];
} }
}
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {

View file

@ -2184,6 +2184,45 @@ static NSColor *shadowCol;
* NSCoding protocol * NSCoding protocol
*/ */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{
if([aCoder allowsKeyedCoding])
{
unsigned long cFlags = 0;
unsigned int cFlags2 = 0;
[aCoder encodeObject: _contents forKey: @"NSContents"];
// flags
cFlags |= [self wraps] ? 0x40 : 0;
cFlags |= [self isScrollable] ? 0x100000 : 0;
cFlags |= [self isSelectable] ? 0x200001 : 0;
cFlags |= [self isBezeled] ? 0x400000 : 0;
cFlags |= [self isBordered] ? 0x800000 : 0;
cFlags |= ([self type] == NSTextCellType) ? 0x4000000 : 0;
cFlags |= [self isContinuous] ? 0x40000 : 0;
cFlags |= [self isEditable] ? 0x10000000 : 0;
cFlags |= ([self isEnabled] == NO) ? 0x20000000 : 0;
cFlags |= ([self state] == NSOnState) ? 0x80000000 : 0;
cFlags |= [self isHighlighted] ? 0x40000000 : 0;
[aCoder encodeInt: cFlags forKey: @"NSCellFlags"];
// flags part 2
cFlags2 |= [self sendsActionOnEndEditing] ? 0x400000 : 0;
cFlags2 |= [self allowsMixedState] ? 0x1000000 : 0;
cFlags2 |= [self refusesFirstResponder] ? 0x2000000 : 0;
cFlags2 |= ([self alignment] == NSRightTextAlignment) ? 0x4000000 : 0;
cFlags2 |= ([self alignment] == NSCenterTextAlignment) ? 0x8000000 : 0;
cFlags2 |= ([self alignment] == NSJustifiedTextAlignment) ? 0xC000000 : 0;
cFlags2 |= ([self alignment] == NSNaturalTextAlignment) ? 0x10000000 : 0;
cFlags2 |= [self importsGraphics] ? 0x20000000 : 0;
cFlags2 |= [self allowsEditingTextAttributes] ? 0x40000000 : 0;
[aCoder encodeInt: cFlags2 forKey: @"NSCellFlags2"];
// font and formatter.
[aCoder encodeObject: [self font] forKey: @"NSSupport"];
[aCoder encodeObject: [self formatter] forKey: @"NSFormatter"];
}
else
{ {
BOOL flag; BOOL flag;
unsigned int tmp_int; unsigned int tmp_int;
@ -2245,6 +2284,7 @@ static NSColor *shadowCol;
[aCoder encodeValueOfObjCType: @encode(id) at: &_menu]; [aCoder encodeValueOfObjCType: @encode(id) at: &_menu];
[aCoder encodeValueOfObjCType: @encode(id) at: &_represented_object]; [aCoder encodeValueOfObjCType: @encode(id) at: &_represented_object];
} }
}
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {

View file

@ -1654,6 +1654,13 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
{ {
[super encodeWithCoder: coder]; [super encodeWithCoder: coder];
if([coder allowsKeyedCoding])
{
[coder encodeBool: [self hasVerticalScroller] forKey: @"NSHasVerticalScroller"];
[coder encodeInt: [self numberOfVisibleItems] forKey: @"NSVisibleItemCount"];
}
else
{
[coder encodeValueOfObjCType: @encode(id) at: &_popUpList]; [coder encodeValueOfObjCType: @encode(id) at: &_popUpList];
[coder encodeValueOfObjCType: @encode(BOOL) at: &_usesDataSource]; [coder encodeValueOfObjCType: @encode(BOOL) at: &_usesDataSource];
[coder encodeValueOfObjCType: @encode(BOOL) at: &_hasVerticalScroller]; [coder encodeValueOfObjCType: @encode(BOOL) at: &_hasVerticalScroller];
@ -1667,6 +1674,7 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
if (_usesDataSource == YES) if (_usesDataSource == YES)
[coder encodeConditionalObject: _dataSource]; [coder encodeConditionalObject: _dataSource];
} }
}
/** /**
* Initializes the combo box cell with data linked to <var>decoder</var>. Take * Initializes the combo box cell with data linked to <var>decoder</var>. Take

View file

@ -843,11 +843,18 @@ static Class actionCellClass;
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if([aCoder allowsKeyedCoding])
{
[aCoder encodeObject: [self cell] forKey: @"NSCell"];
[aCoder encodeBool: [self isEnabled] forKey: @"NSEnabled"];
}
else
{
[aCoder encodeValueOfObjCType: @encode(int) at: &_tag]; [aCoder encodeValueOfObjCType: @encode(int) at: &_tag];
[aCoder encodeObject: _cell]; [aCoder encodeObject: _cell];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_ignoresMultiClick]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_ignoresMultiClick];
} }
}
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {

View file

@ -2677,7 +2677,38 @@ static SEL getSel;
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if([aCoder allowsKeyedCoding])
{
GSMatrixFlags matrixFlags;
unsigned int mFlags = 0;
[aCoder encodeObject: [self backgroundColor] forKey: @"NSBackgroundColor"];
[aCoder encodeObject: [self cellBackgroundColor] forKey: @"NSCellBackgroundColor"];
[aCoder encodeObject: [self prototype] forKey: @"NSProtoCell"];
[aCoder encodeObject: NSStringFromClass([self cellClass]) forKey: @"NSCellClass"];
[aCoder encodeSize: _cellSize forKey: @"NSCellSize"];
[aCoder encodeSize: _intercell forKey: @"NSIntercellSpacing"];
/// set the flags...
matrixFlags.isRadio = ([self mode] == NSRadioModeMatrix);
matrixFlags.isList = ([self mode] == NSListModeMatrix);
matrixFlags.isHighlight = ([self mode] == NSHighlightModeMatrix);
matrixFlags.allowsEmptySelection = [self allowsEmptySelection];
matrixFlags.selectionByRect = [self isSelectionByRect];
matrixFlags.drawCellBackground = [self drawsCellBackground];
matrixFlags.drawBackground = [self drawsBackground];
matrixFlags.tabKeyTraversesCells = _tabKeyTraversesCells;
memcpy((void *)&mFlags,(void *)&matrixFlags,sizeof(unsigned int));
[aCoder encodeInt: mFlags forKey: @"NSMatrixFlags"];
[aCoder encodeInt: _numCols forKey: @"NSNumCols"];
[aCoder encodeInt: _numRows forKey: @"NSNumRows"];
[aCoder encodeObject: [self cells] forKey: @"NSCells"];
[aCoder encodeInt: _selectedColumn forKey: @"NSSelectedCol"];
[aCoder encodeInt: _selectedRow forKey: @"NSSelectedRow"];
}
else
{
[aCoder encodeValueOfObjCType: @encode (int) at: &_mode]; [aCoder encodeValueOfObjCType: @encode (int) at: &_mode];
[aCoder encodeValueOfObjCType: @encode (BOOL) at: &_allowsEmptySelection]; [aCoder encodeValueOfObjCType: @encode (BOOL) at: &_allowsEmptySelection];
[aCoder encodeValueOfObjCType: @encode (BOOL) at: &_selectionByRect]; [aCoder encodeValueOfObjCType: @encode (BOOL) at: &_selectionByRect];
@ -2708,14 +2739,15 @@ static SEL getSel;
/* We do not encode information on selected cells, because this is saved /* We do not encode information on selected cells, because this is saved
with the cells themselves */ with the cells themselves */
} }
}
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
Class class; Class class;
id cell; id cell;
int rows, columns; int rows = 0, columns = 0;
NSArray *array; NSArray *array;
int i, count; int i = 0, count = 0;
[super initWithCoder: aDecoder]; [super initWithCoder: aDecoder];

View file

@ -5136,13 +5136,14 @@ static inline float computePeriod(NSPoint mouseLocationWin,
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder];
if ([aCoder allowsKeyedCoding]) if ([aCoder allowsKeyedCoding])
{ {
unsigned int vFlags = 0; // (raw >> 26); // filter out settings not pertinent to us. unsigned int vFlags = 0; // (raw >> 26); // filter out settings not pertinent to us.
NSSize intercellSpacing = [self intercellSpacing]; NSSize intercellSpacing = [self intercellSpacing];
// make sure the corner view is properly encoded...
[(NSKeyedArchiver *)aCoder setClassName: @"_NSCornerView" forClass: [GSTableCornerView class]];
[super encodeWithCoder: aCoder];
[aCoder encodeObject: [self dataSource] forKey: @"NSDataSource"]; [aCoder encodeObject: [self dataSource] forKey: @"NSDataSource"];
[aCoder encodeObject: [self delegate] forKey: @"NSDelegate"]; [aCoder encodeObject: [self delegate] forKey: @"NSDelegate"];
[aCoder encodeObject: [self target] forKey: @"NSTarget"]; [aCoder encodeObject: [self target] forKey: @"NSTarget"];
@ -5178,6 +5179,7 @@ static inline float computePeriod(NSPoint mouseLocationWin,
} }
else else
{ {
[super encodeWithCoder: aCoder];
[aCoder encodeConditionalObject: _dataSource]; [aCoder encodeConditionalObject: _dataSource];
[aCoder encodeObject: _tableColumns]; [aCoder encodeObject: _tableColumns];
[aCoder encodeObject: _gridColor]; [aCoder encodeObject: _gridColor];

View file

@ -462,5 +462,22 @@ framework intact.
} }
} }
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
NSSize size = _containerRect.size;
int flags = ((_widthTracksTextView)?1:0) |
((_heightTracksTextView)?2:0) |
((_observingFrameChanges)?4:0);
[coder encodeObject: _textView forKey: @"NSTextView"];
[coder encodeFloat: size.width forKey: @"NSWidth"];
[coder encodeInt: flags forKey: @"NSTCFlags"];
// TODO: Add layout manager encoding, if needed...
}
}
@end /* NSTextContainer */ @end /* NSTextContainer */

View file

@ -353,4 +353,17 @@ static NSNotificationCenter *nc = nil;
return self; return self;
} }
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[coder encodeObject: [self delegate] forKey: @"NSDelegate"];
[coder encodeObject: [self string] forKey: @"NSString"];
}
else
{
[super encodeWithCoder: coder];
}
}
@end @end

View file

@ -147,6 +147,35 @@ Interface for a bunch of internal methods that need to be cleaned up.
@implementation NSTextViewSharedData @implementation NSTextViewSharedData
- (id) initWithTextView: (NSTextView *)tv
{
if((self = [super init]) != nil)
{
flags = (([tv isEditable]?0x01:0) |
([tv isSelectable]?0x02:0) |
([tv isRichText]?0x04:0) |
([tv importsGraphics]?0x08:0) |
([tv isFieldEditor]?0x10:0) |
([tv usesFontPanel]?0x20:0) |
([tv isRulerVisible]?0x40:0) |
([tv usesRuler]?0x100:0) |
([tv drawsBackground]?0x800:0) |
([tv smartInsertDeleteEnabled]?0x2000000:0) |
([tv allowsUndo]?0x40000000:0));
ASSIGN(backgroundColor,[tv backgroundColor]);
ASSIGN(paragraphStyle,[NSParagraphStyle defaultParagraphStyle]);
ASSIGN(insertionColor,[tv insertionPointColor]);
ASSIGN(markAttr,[tv markedTextAttributes]);
ASSIGN(selectedAttr,[tv selectedTextAttributes]);
linkAttr = nil;
textView = tv;
}
return self;
}
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
if ([aDecoder allowsKeyedCoding]) if ([aDecoder allowsKeyedCoding])
@ -167,6 +196,21 @@ Interface for a bunch of internal methods that need to be cleaned up.
return self; return self;
} }
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
[coder encodeObject: backgroundColor forKey: @"NSBackgoundColor"];
[coder encodeObject: paragraphStyle forKey: @"NSDefaultParagraphStyle"];
[coder encodeInt: flags forKey: @"NSFlags"];
[coder encodeObject: markAttr forKey: @"NSMarkedAttributes"];
[coder encodeObject: selectedAttr forKey: @"NSSelectedAttributes"];
[coder encodeObject: insertionColor forKey: @"NSInsertionColor"];
// TODO: Encode/Decode link attributes...
}
}
- (void) dealloc - (void) dealloc
{ {
RELEASE(backgroundColor); RELEASE(backgroundColor);
@ -652,6 +696,20 @@ that makes decoding and encoding compatible with the old code.
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if([aCoder allowsKeyedCoding])
{
NSTextViewSharedData *tvsd = [[NSTextViewSharedData alloc] initWithTextView: self];
[aCoder encodeConditionalObject: _delegate forKey: @"NSDelegate"];
[aCoder encodeSize: [self maxSize] forKey: @"NSMaxSize"];
[aCoder encodeSize: [self minSize] forKey: @"NSMinSize"];
[aCoder encodeObject: tvsd forKey: @"NSSharedData"];
[aCoder encodeObject: [self textStorage] forKey: @"NSTextStorage"];
[aCoder encodeObject: [self textContainer] forKey: @"NSTextContainer"];
[aCoder encodeInt: 0 forKey: @"NSTVFlags"]; // no delegates, etc... set to zero.
}
else
{
[aCoder encodeConditionalObject: _delegate]; [aCoder encodeConditionalObject: _delegate];
flag = _tf.is_field_editor; flag = _tf.is_field_editor;
@ -692,6 +750,7 @@ that makes decoding and encoding compatible with the old code.
flag = [_textContainer heightTracksTextView]; flag = [_textContainer heightTracksTextView];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
} }
}
- (id) initWithCoder: (NSCoder *)aDecoder - (id) initWithCoder: (NSCoder *)aDecoder
{ {