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:
gcasa 2004-10-18 01:48:15 +00:00
parent 31eeedc9c5
commit c0dc199651
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> 2004-10-17 Adrian Robert <arobert@cogsci.ucsd.edu>
* Source/Functions.m (NSBestDepth): Check outarg exactMatch is * Source/Functions.m (NSBestDepth): Check outarg exactMatch is
non-null before setting. non-null before setting.
* Source/NSFont.m (getNSFont): Use defaultSize for 'fontSize' * 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 will be removed from the GUI library in the next few versions as
they need to be phased out gradually. they need to be phased out gradually.
<p/> <p/>
If you have any .gorm files which were created using custom classes, you If you have any older .gorm files which were created using custom classes,
should load them into Gorm and save them so that they will use the new 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 system. Updating the .gorm files should be as easy as that. These
classes are included ONLY for backwards compatibility. classes are included ONLY for backwards compatibility.
</abstract> </abstract>

View file

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

View file

@ -338,18 +338,51 @@
*/ */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
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) [aCoder encodeValueOfObjCType: @encode(NSInterfaceStyle)
at: &_interface_style]; at: &_interface_style];
[aCoder encodeObject: _menu]; [aCoder encodeObject: _menu];
}
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
id obj; id obj;
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) [aDecoder decodeValueOfObjCType: @encode(NSInterfaceStyle)
at: &_interface_style]; at: &_interface_style];
obj = [aDecoder decodeObject]; obj = [aDecoder decodeObject];
}
[self setMenu: obj]; [self setMenu: obj];
return self; return self;

View file

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

View file

@ -3736,9 +3736,43 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
*/ */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
if([aCoder allowsKeyedCoding])
{
int vFlags = 0;
// 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]; [super encodeWithCoder: aCoder];
NSDebugLLog(@"NSView", @"NSView: start encoding\n");
[aCoder encodeRect: _frame]; [aCoder encodeRect: _frame];
[aCoder encodeRect: _bounds]; [aCoder encodeRect: _bounds];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_rotated_from_base]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_rotated_from_base];
@ -3751,23 +3785,32 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
[aCoder encodeConditionalObject: [self previousKeyView]]; [aCoder encodeConditionalObject: [self previousKeyView]];
[aCoder encodeObject: _sub_views]; [aCoder encodeObject: _sub_views];
NSDebugLLog(@"NSView", @"NSView: finish encoding\n"); NSDebugLLog(@"NSView", @"NSView: finish encoding\n");
}
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (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]) if ([aDecoder allowsKeyedCoding])
{ {
NSRect frame = NSZeroRect; NSView *prevKeyView = [aDecoder decodeObjectForKey: @"NSPreviousKeyView"];
//id next = [aDecoder decodeObjectForKey: @"NSNextResponder"];
//NSView *superView = [aDecoder decodeObjectForKey: @"NSSuperview"];
NSView *nextKeyView = [aDecoder decodeObjectForKey: @"NSNextKeyView"]; NSView *nextKeyView = [aDecoder decodeObjectForKey: @"NSNextKeyView"];
NSArray *subViews = [aDecoder decodeObjectForKey: @"NSSubviews"]; NSArray *subViews = [aDecoder decodeObjectForKey: @"NSSubviews"];
if ([aDecoder containsValueForKey: @"NSFrame"]) 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) if (subViews != nil)
{ {
@ -3783,6 +3826,10 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
{ {
[self setNextKeyView: nextKeyView]; [self setNextKeyView: nextKeyView];
} }
if (prevKeyView != nil)
{
[self setPreviousKeyView: prevKeyView];
}
if ([aDecoder containsValueForKey: @"NSvFlags"]) if ([aDecoder containsValueForKey: @"NSvFlags"])
{ {
int vFlags = [aDecoder decodeIntForKey: @"NSvFlags"]; int vFlags = [aDecoder decodeIntForKey: @"NSvFlags"];
@ -3801,18 +3848,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
NSView *sub; NSView *sub;
NSArray *subs; NSArray *subs;
self = [super initWithCoder: aDecoder];
NSDebugLLog(@"NSView", @"NSView: start decoding\n"); NSDebugLLog(@"NSView", @"NSView: start decoding\n");
_frame = [aDecoder decodeRect]; _frame = [aDecoder decodeRect];
_bounds.origin = NSZeroPoint; _bounds.origin = NSZeroPoint;
_bounds.size = _frame.size; _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]; [_frameMatrix setFrameOrigin: _frame.origin];
rect = [aDecoder decodeRect]; rect = [aDecoder decodeRect];

View file

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