mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
* Headers/Additions/GNUstepGUI/GSNibLoading.h: Added new method
nibInstantiateWithCoder: to do the initialization normally done in NSView when not in IB/Gorm. * Source/GSNibLoading.m: Added implementation of new method and also re-wrote part of NSCustomView. * Source/NSView.m: Added an NSAssert to assure that no subview ever decoded is an NSCustomView. --- Moved decoding of custom view attributes here so that it can cleanly initialize everything to ensure that the view works properly. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27281 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
97d5040a02
commit
05bec8c892
4 changed files with 149 additions and 66 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2008-12-12 02:04-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSNibLoading.h: Added new method
|
||||
nibInstantiateWithCoder: to do the initialization normally done
|
||||
in NSView when not in IB/Gorm.
|
||||
* Source/GSNibLoading.m: Added implementation of new method and
|
||||
also re-wrote part of NSCustomView.
|
||||
* Source/NSView.m: Added an NSAssert to assure that no subview
|
||||
ever decoded is an NSCustomView.
|
||||
|
||||
2008-12-12 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSBitmapImageRep.m (-_convertToFormatBitsPerSample:...):
|
||||
|
|
|
@ -218,6 +218,7 @@ typedef struct _GSWindowTemplateFlags
|
|||
- (void) setExtension: (NSString *)view;
|
||||
- (NSString *)extension;
|
||||
- (id)nibInstantiate;
|
||||
- (id)nibInstantiateWithCoder: (NSCoder *)coder;
|
||||
@end
|
||||
|
||||
@interface NSCustomResource : NSObject <NSCoding>
|
||||
|
|
|
@ -65,6 +65,31 @@
|
|||
|
||||
static BOOL _isInInterfaceBuilder = NO;
|
||||
|
||||
@interface NSKeyedUnarchiver (NSClassSwapperPrivate)
|
||||
- (BOOL) replaceObject: (id)oldObj withObject: (id)newObj;
|
||||
- (NSDictionary *)keyMap;
|
||||
- (Class) replacementClassForClassName: (NSString *)className;
|
||||
@end
|
||||
|
||||
@interface NSApplication (NibCompatibility)
|
||||
- (void) _setMainMenu: (NSMenu*)aMenu;
|
||||
@end
|
||||
|
||||
@interface NSView (NibCompatibility)
|
||||
- (void) _fixSubviews;
|
||||
@end
|
||||
|
||||
/* Correct some instances where the ":" is missing from the method name in the label */
|
||||
@interface NSNibControlConnector (NibCompatibility)
|
||||
- (void) instantiateWithInstantiator: (id<GSInstantiator>)instantiator;
|
||||
@end
|
||||
|
||||
@interface NSDecimalNumberPlaceholder : NSObject
|
||||
@end
|
||||
|
||||
@interface _NSCornerView : NSView
|
||||
@end
|
||||
|
||||
@interface NSMenu (NibCompatibility)
|
||||
- (void) _setGeometry;
|
||||
- (void) _setMain: (BOOL)isMain;
|
||||
|
@ -147,10 +172,6 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
@end
|
||||
|
||||
@interface NSApplication (NibCompatibility)
|
||||
- (void) _setMainMenu: (NSMenu*)aMenu;
|
||||
@end
|
||||
|
||||
@implementation NSApplication (NibCompatibility)
|
||||
- (void) _setMainMenu: (NSMenu*)aMenu
|
||||
{
|
||||
|
@ -173,10 +194,6 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
@end
|
||||
|
||||
@interface NSView (NibCompatibility)
|
||||
- (void) _fixSubviews;
|
||||
@end
|
||||
|
||||
@implementation NSView (NibCompatibility)
|
||||
- (void) _setWindow: (id) w
|
||||
{
|
||||
|
@ -818,45 +835,87 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
|
||||
- (id) nibInstantiate
|
||||
{
|
||||
if (_view == nil)
|
||||
Class aClass;
|
||||
|
||||
if ([NSClassSwapper isInInterfaceBuilder])
|
||||
{
|
||||
Class aClass;
|
||||
_view = self;
|
||||
return self;
|
||||
}
|
||||
else
|
||||
{
|
||||
aClass = NSClassFromString(_className);
|
||||
}
|
||||
|
||||
// If the class name is nil, assume NSView.
|
||||
if(_className == nil)
|
||||
{
|
||||
aClass = [NSView class];
|
||||
}
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
else
|
||||
{
|
||||
_view = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]];
|
||||
}
|
||||
|
||||
return _view;
|
||||
}
|
||||
|
||||
- (id) awakeAfterUsingCoder: (NSCoder *)coder
|
||||
{
|
||||
return _view;
|
||||
}
|
||||
|
||||
- (id) nibInstantiateWithCoder: (NSCoder *)coder
|
||||
{
|
||||
if([NSClassSwapper isInInterfaceBuilder])
|
||||
{
|
||||
return _view;
|
||||
}
|
||||
else if ([coder allowsKeyedCoding])
|
||||
{
|
||||
NSArray *subs = nil;
|
||||
id nextKeyView = nil;
|
||||
id prevKeyView = nil;
|
||||
NSEnumerator *en = nil;
|
||||
id v = nil;
|
||||
|
||||
prevKeyView = [coder decodeObjectForKey: @"NSPreviousKeyView"];
|
||||
nextKeyView = [coder decodeObjectForKey: @"NSNextKeyView"];
|
||||
if (nextKeyView != nil)
|
||||
{
|
||||
[self setNextKeyView: nextKeyView];
|
||||
}
|
||||
if (prevKeyView != nil)
|
||||
{
|
||||
[self setPreviousKeyView: prevKeyView];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSvFlags"])
|
||||
{
|
||||
int vFlags = [coder decodeIntForKey: @"NSvFlags"];
|
||||
[_view setAutoresizingMask: vFlags & 0x3F];
|
||||
[_view setAutoresizesSubviews: ((vFlags & 0x100) == 0x100)];
|
||||
[_view setHidden: ((vFlags & 0x80000000) == 0x80000000)];
|
||||
}
|
||||
|
||||
if ([NSClassSwapper isInInterfaceBuilder])
|
||||
{
|
||||
_view = self;
|
||||
return self;
|
||||
}
|
||||
else
|
||||
{
|
||||
aClass = NSClassFromString(_className);
|
||||
}
|
||||
|
||||
if (aClass == nil)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Unable to find class '%@'", _className];
|
||||
}
|
||||
else
|
||||
{
|
||||
_view = [[aClass allocWithZone: NSDefaultMallocZone()] initWithFrame: [self frame]];
|
||||
[_view setAutoresizingMask: [self autoresizingMask]];
|
||||
[_view setAutoresizesSubviews: [self autoresizesSubviews]];
|
||||
[_view setHidden: [self isHidden]];
|
||||
[_view setNextResponder: [self nextResponder]];
|
||||
// [[self superview] replaceSubview: self with: _view]; // replace the old view...
|
||||
|
||||
if (_rFlags.has_subviews)
|
||||
{
|
||||
NSEnumerator *en = [[self subviews] objectEnumerator];
|
||||
id v = nil;
|
||||
|
||||
while((v = [en nextObject]) == nil)
|
||||
{
|
||||
[_view addSubview: v];
|
||||
}
|
||||
}
|
||||
}
|
||||
[_view setNextResponder: [self nextResponder]];
|
||||
|
||||
subs = [coder decodeObjectForKey: @"NSSubviews"];
|
||||
en = [subs objectEnumerator];
|
||||
while((v = [en nextObject]) != nil)
|
||||
{
|
||||
[_view addSubview: v];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Called NSCustomView awakeAfterUsingCoder with non-keyed archiver."];
|
||||
}
|
||||
|
||||
return _view;
|
||||
|
@ -864,19 +923,46 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
self = [super initWithCoder: coder];
|
||||
// if in interface builder, then initialize as normal.
|
||||
if([NSClassSwapper isInInterfaceBuilder])
|
||||
{
|
||||
self = [super initWithCoder: coder];
|
||||
}
|
||||
|
||||
if (self != nil)
|
||||
{
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
// get the super stuff without calling super...
|
||||
if ([coder containsValueForKey: @"NSFrame"])
|
||||
{
|
||||
_frame = [coder decodeRectForKey: @"NSFrame"];
|
||||
}
|
||||
else
|
||||
{
|
||||
_frame = NSZeroRect;
|
||||
if ([coder containsValueForKey: @"NSFrameSize"])
|
||||
{
|
||||
_frame.size = [coder decodeSizeForKey: @"NSFrameSize"];
|
||||
}
|
||||
}
|
||||
|
||||
ASSIGN(_className, [coder decodeObjectForKey: @"NSClassName"]);
|
||||
ASSIGN(_extension, [coder decodeObjectForKey: @"NSExtension"]);
|
||||
|
||||
[self nibInstantiate];
|
||||
|
||||
if([self nibInstantiate] != nil)
|
||||
{
|
||||
[self nibInstantiateWithCoder: coder];
|
||||
}
|
||||
|
||||
// Prevent the case where we get back an NSCustomView.
|
||||
// NSAssert((([NSClassSwapper isInInterfaceBuilder] == NO) &&
|
||||
// ([_view class] != [NSCustomView class])), NSInvalidArgumentException);
|
||||
|
||||
if(self != _view)
|
||||
{
|
||||
AUTORELEASE(self);
|
||||
[coder replaceObject: self withObject: _view];
|
||||
[(NSKeyedUnarchiver *)coder replaceObject: self withObject: _view];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -977,12 +1063,6 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
@end
|
||||
|
||||
@interface NSKeyedUnarchiver (NSClassSwapperPrivate)
|
||||
- (BOOL) replaceObject: (id)oldObj withObject: (id)newObj;
|
||||
- (NSDictionary *)keyMap;
|
||||
- (Class) replacementClassForClassName: (NSString *)className;
|
||||
@end
|
||||
|
||||
@implementation NSKeyedUnarchiver (NSClassSwapperPrivate)
|
||||
- (BOOL) replaceObject: (id)oldObj withObject: (id)newObj
|
||||
{
|
||||
|
@ -1191,11 +1271,6 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
@end
|
||||
|
||||
/* Correct some instances where the ":" is missing from the method name in the label */
|
||||
@interface NSNibControlConnector (NibCompatibility)
|
||||
- (void) instantiateWithInstantiator: (id<GSInstantiator>)instantiator;
|
||||
@end
|
||||
|
||||
@implementation NSNibControlConnector (NibCompatibility)
|
||||
- (void) instantiateWithInstantiator: (id<GSInstantiator>)instantiator
|
||||
{
|
||||
|
@ -1729,9 +1804,6 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
}
|
||||
@end
|
||||
|
||||
@interface NSDecimalNumberPlaceholder : NSObject
|
||||
@end
|
||||
|
||||
@implementation NSDecimalNumberPlaceholder
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
|
@ -1775,9 +1847,6 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
// ...dummy/placeholder classes...
|
||||
// overridden in NSTableView to be GSTableCornerView,
|
||||
// but the class needs to be present to be overridden.
|
||||
@interface _NSCornerView : NSView
|
||||
@end
|
||||
|
||||
@implementation _NSCornerView
|
||||
@end
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
#include "AppKit/PSOperators.h"
|
||||
#include "GNUstepGUI/GSDisplayServer.h"
|
||||
#include "GNUstepGUI/GSTrackingRect.h"
|
||||
#include "GNUstepGUI/GSNibLoading.h"
|
||||
#include "GSToolTips.h"
|
||||
#include "GSBindingHelpers.h"
|
||||
|
||||
|
@ -4471,6 +4472,8 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
|
|||
e = [subs objectEnumerator];
|
||||
while ((sub = [e nextObject]) != nil)
|
||||
{
|
||||
NSAssert([sub class] != [NSCustomView class],
|
||||
NSInternalInconsistencyException);
|
||||
NSAssert([sub window] == nil,
|
||||
NSInternalInconsistencyException);
|
||||
NSAssert([sub superview] == nil,
|
||||
|
|
Loading…
Reference in a new issue