Improvements in keyed coding and correction for NSCell formatter unarchiving issue.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20235 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-10-18 01:48:15 +00:00
parent 51256bbe12
commit 208c87b881
7 changed files with 160 additions and 51 deletions

View file

@ -1,4 +1,21 @@
2004-10-17 Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSCell.m: Added code to [NSCell initWithCoder:] which
properly retains the formatter and menu.
* Source/GSNibCompatibility.m: Changed comment.
* Source/NSResponder.m: Added keyed archiving implementation in
initWithCoder:
* Source/NSTextView.m: Improved implementation of keyed coding
for NSTextView. Also preparing to add details discovered about
the flag settings.
* Source/NSView.m: Improved NSView keyed decoding. Also made
sure that [super initWithCoder:] is called in that method for both
the keyed and non-keyed archiving (as it should be).
* Source/NSWindow.m: Added implementation of undo: and redo: to
NSWindow.m.
2004-10-17 Adrian Robert <arobert@cogsci.ucsd.edu>
* Source/Functions.m (NSBestDepth): Check outarg exactMatch is
non-null before setting.
* Source/NSFont.m (getNSFont): Use defaultSize for 'fontSize'

View file

@ -6,8 +6,8 @@
They will be removed from the GUI library in the next few versions as
they need to be phased out gradually.
<p/>
If you have any .gorm files which were created using custom classes, you
should load them into Gorm and save them so that they will use the new
If you have any older .gorm files which were created using custom classes,
you should load them into Gorm and save them so that they will use the new
system. Updating the .gorm files should be as easy as that. These
classes are included ONLY for backwards compatibility.
</abstract>

View file

@ -2079,7 +2079,8 @@ static NSColor *shadowCol;
{
BOOL flag;
unsigned int tmp_int;
id formatter, menu;
[aDecoder decodeValueOfObjCType: @encode(id) at: &_contents];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_cell_image];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_font];
@ -2132,10 +2133,12 @@ static NSColor *shadowCol;
[aDecoder decodeValueOfObjCType: @encode(unsigned int)
at: &_mouse_down_flags];
[aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &_action_mask];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_formatter];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_menu];
[aDecoder decodeValueOfObjCType: @encode(id) at: &formatter];
[self setFormatter: formatter];
[aDecoder decodeValueOfObjCType: @encode(id) at: &menu];
[self setMenu: menu];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_represented_object];
if (_formatter != nil)
{
NSString *contents;

View file

@ -338,18 +338,51 @@
*/
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[aCoder encodeValueOfObjCType: @encode(NSInterfaceStyle)
at: &_interface_style];
[aCoder encodeObject: _menu];
if([aCoder allowsKeyedCoding])
{
if(_interface_style != NSNoInterfaceStyle)
{
[aCoder encodeInt: _interface_style
forKey: @"NSInterfaceStyle"];
}
if([self menu] != nil)
{
[aCoder encodeObject: [self menu]
forKey: @"NSMenu"];
}
}
else
{
[aCoder encodeValueOfObjCType: @encode(NSInterfaceStyle)
at: &_interface_style];
[aCoder encodeObject: _menu];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
id obj;
[aDecoder decodeValueOfObjCType: @encode(NSInterfaceStyle)
at: &_interface_style];
obj = [aDecoder decodeObject];
if([aDecoder allowsKeyedCoding])
{
if([aDecoder containsValueForKey: @"NSInterfaceStyle"])
{
_interface_style = [aDecoder decodeIntForKey: @"NSInterfaceStyle"];
}
if([aDecoder containsValueForKey: @"NSMenu"])
{
obj = [aDecoder decodeObjectForKey: @"NSMenu"];
}
}
else
{
[aDecoder decodeValueOfObjCType: @encode(NSInterfaceStyle)
at: &_interface_style];
obj = [aDecoder decodeObject];
}
[self setMenu: obj];
return self;

View file

@ -133,6 +133,7 @@ Interface for a bunch of internal methods that need to be cleaned up.
NSArray *linkAttr;
NSArray *markAttr;
NSArray *selectedAttr;
NSTextView *textView;
}
@end
@ -656,20 +657,24 @@ that makes decoding and encoding compatible with the old code.
{
[self setMaxSize: [aDecoder decodeSizeForKey: @"NSMaxSize"]];
}
// Is this a mistype from Apple?
if ([aDecoder containsValueForKey: @"NSMinize"])
{
// it's NSMinize in pre-10.3 formats.
[self setMinSize: [aDecoder decodeSizeForKey: @"NSMinize"]];
}
if ([aDecoder containsValueForKey: @"NSMinSize"])
{
// However, if NSMinSize is present we want to use it.
[self setMinSize: [aDecoder decodeSizeForKey: @"NSMinSize"]];
}
if ([aDecoder containsValueForKey: @"NSTextContainer"])
{
[self setTextContainer: [aDecoder decodeObjectForKey: @"NSTextContainer"]];
}
// FIXME set the flags, shared data, storage
if ([aDecoder containsValueForKey: @"NSTVFlags"])
{
//int vFlags = [aDecoder decodeIntForKey: @"NSTVFlags"];
int vFlags = [aDecoder decodeIntForKey: @"NSTVFlags"];
// FIXME set the flags
}
if ([aDecoder containsValueForKey: @"NSSharedData"])

View file

@ -3736,41 +3736,84 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
*/
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
if([aCoder allowsKeyedCoding])
{
int vFlags = 0;
NSDebugLLog(@"NSView", @"NSView: start encoding\n");
[aCoder encodeRect: _frame];
[aCoder encodeRect: _bounds];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_rotated_from_base];
[aCoder encodeValueOfObjCType: @encode(BOOL)
at: &_is_rotated_or_scaled_from_base];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_post_frame_changes];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizes_subviews];
[aCoder encodeValueOfObjCType: @encode(unsigned int) at: &_autoresizingMask];
[aCoder encodeConditionalObject: [self nextKeyView]];
[aCoder encodeConditionalObject: [self previousKeyView]];
[aCoder encodeObject: _sub_views];
NSDebugLLog(@"NSView", @"NSView: finish encoding\n");
// encoding
[aCoder encodeConditionalObject: [self nextKeyView]
forKey: @"NSNextKeyView"];
[aCoder encodeConditionalObject: [self previousKeyView]
forKey: @"NSPreviousKeyView"];
[aCoder encodeObject: _sub_views
forKey: @"NSSubviews"];
[aCoder encodeRect: _frame
forKey: @"NSFrame"];
// autosizing masks.
vFlags = _autoresizingMask;
// add the autoresize flag.
if(_autoresizes_subviews)
{
vFlags |= 0x100;
}
// add the hidden flag
if(_is_hidden)
{
vFlags |= 0x80000000;
}
[aCoder encodeInt: vFlags
forKey: @"NSvFlags"];
}
else
{
NSDebugLLog(@"NSView", @"NSView: start encoding\n");
[super encodeWithCoder: aCoder];
[aCoder encodeRect: _frame];
[aCoder encodeRect: _bounds];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_rotated_from_base];
[aCoder encodeValueOfObjCType: @encode(BOOL)
at: &_is_rotated_or_scaled_from_base];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_post_frame_changes];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizes_subviews];
[aCoder encodeValueOfObjCType: @encode(unsigned int) at: &_autoresizingMask];
[aCoder encodeConditionalObject: [self nextKeyView]];
[aCoder encodeConditionalObject: [self previousKeyView]];
[aCoder encodeObject: _sub_views];
NSDebugLLog(@"NSView", @"NSView: finish encoding\n");
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
// decode the superclass...
[super initWithCoder: aDecoder];
// initialize these here, since they're needed in either case.
_frameMatrix = [NSAffineTransform new]; // Map fromsuperview to frame
_boundsMatrix = [NSAffineTransform new]; // Map fromsuperview to bounds
_matrixToWindow = [NSAffineTransform new]; // Map to window coordinates
_matrixFromWindow = [NSAffineTransform new];// Map from window coordinates
if ([aDecoder allowsKeyedCoding])
{
NSRect frame = NSZeroRect;
//id next = [aDecoder decodeObjectForKey: @"NSNextResponder"];
//NSView *superView = [aDecoder decodeObjectForKey: @"NSSuperview"];
NSView *prevKeyView = [aDecoder decodeObjectForKey: @"NSPreviousKeyView"];
NSView *nextKeyView = [aDecoder decodeObjectForKey: @"NSNextKeyView"];
NSArray *subViews = [aDecoder decodeObjectForKey: @"NSSubviews"];
if ([aDecoder containsValueForKey: @"NSFrame"])
{
frame = [aDecoder decodeRectForKey: @"NSFrame"];
{
_frame = [aDecoder decodeRectForKey: @"NSFrame"];
[_frameMatrix setFrameOrigin: _frame.origin];
}
self = [self initWithFrame: frame];
self = [self initWithFrame: _frame];
if (subViews != nil)
{
{
NSEnumerator *enumerator = [subViews objectEnumerator];
NSView *sub;
@ -3780,13 +3823,17 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
}
}
if (nextKeyView != nil)
{
{
[self setNextKeyView: nextKeyView];
}
if (prevKeyView != nil)
{
[self setPreviousKeyView: prevKeyView];
}
if ([aDecoder containsValueForKey: @"NSvFlags"])
{
{
int vFlags = [aDecoder decodeIntForKey: @"NSvFlags"];
// We are lucky here, Apple use the same constants
// in the lower bits of the flags
[self setAutoresizingMask: vFlags & 0x3F];
@ -3797,27 +3844,21 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
else
{
NSRect rect;
NSEnumerator *e;
NSEnumerator *e;
NSView *sub;
NSArray *subs;
self = [super initWithCoder: aDecoder];
NSDebugLLog(@"NSView", @"NSView: start decoding\n");
_frame = [aDecoder decodeRect];
_bounds.origin = NSZeroPoint;
_bounds.size = _frame.size;
_frameMatrix = [NSAffineTransform new]; // Map fromsuperview to frame
_boundsMatrix = [NSAffineTransform new]; // Map fromsuperview to bounds
_matrixToWindow = [NSAffineTransform new]; // Map to window coordinates
_matrixFromWindow = [NSAffineTransform new];// Map from window coordinates
[_frameMatrix setFrameOrigin: _frame.origin];
rect = [aDecoder decodeRect];
[self setBounds: rect];
_sub_views = [NSMutableArray new];
_tracking_rects = [NSMutableArray new];
_cursor_rects = [NSMutableArray new];
@ -3842,7 +3883,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
[aDecoder decodeValueOfObjCType: @encode(id) at: &subs];
e = [subs objectEnumerator];
while ((sub = [e nextObject]) != nil)
{
{
NSAssert(sub->_window == nil, NSInternalInconsistencyException);
NSAssert(sub->_super_view == nil, NSInternalInconsistencyException);
[sub viewWillMoveToWindow: _window];

View file

@ -53,6 +53,7 @@
#include "AppKit/NSColor.h"
#include "AppKit/NSColorList.h"
#include "AppKit/NSCursor.h"
#include "AppKit/NSDocumentController.h"
#include "AppKit/NSDocument.h"
#include "AppKit/NSDragging.h"
#include "AppKit/NSFont.h"
@ -4147,6 +4148,15 @@ resetCursorRectsForView(NSView *theView)
return (void *)_windowNum;
}
- (void) undo: (id)sender
{
[[[[NSDocumentController sharedDocumentController] currentDocument] undoManager] undo];
}
- (void) redo: (id)sender
{
[[[[NSDocumentController sharedDocumentController] currentDocument] undoManager] redo];
}
@end
/*