Made a more generic cell replacement algorith for custom classes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21423 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2005-07-08 02:08:16 +00:00
parent 7aac9ffaa4
commit 03dfa955f4
8 changed files with 114 additions and 106 deletions

View file

@ -1,3 +1,17 @@
2005-07-07 22:02 Gregory John Casamento <greg_casamento@yahoo.com>
* GormCore/GormCustomClassInspector.m: In the method
- (void) _replaceCellClassForObject:className: added logic to
automatically replace the cell in a more generic fashion.
* GormCore/GormPrivate.m: Added logic to canSubstituteForClass: to
determine if it's possible for the class passed in to substitute for
the reciever.
* Palettes/2Controls/inspectors.m: Removed canSubstituteForClass:
implementation for NSSecureTextView.
* Palettes/3Containers/GormNSOutlineView.[hm]: Cleaned up
initWithCoder: and encodeWithCoder:.
* Palettes/3Containers/GormNSTableView.[hm]: Ditto
2005-07-07 13:22 Gregory John Casamento <greg_casamento@yahoo.com>
* GormCore/GormControlEditor.m: Removed commented out code

View file

@ -90,7 +90,18 @@
{
if([_classManager isCustomClass: className] == YES)
{
[classes addObject: className];
NSString *superClass = [_classManager nonCustomSuperClassOf: className];
Class cls = NSClassFromString(superClass);
if(cls != nil)
{
if([cls respondsToSelector: @selector(canSubstituteForClass:)])
{
if([cls canSubstituteForClass: parentClass])
{
[classes addObject: className];
}
}
}
}
else if(parentClass != nil)
{
@ -154,42 +165,58 @@
- (void) _replaceCellClassForObject: (id)obj
className: (NSString *)name
{
if([name isEqualToString: @"NSSecureTextField"] ||
[name isEqualToString: @"NSTextField"])
NSString *className = name;
if([[obj class] respondsToSelector: @selector(cellClass)])
{
NSCell *cell = [obj cell];
NSCell *newCell = nil;
BOOL drawsBackground = [object drawsBackground];
// instantiate the cell...
if([name isEqualToString: @"NSSecureTextField"])
if([_classManager isCustomClass: className])
{
newCell = [[NSSecureTextFieldCell alloc] init];
}
else if([name isEqualToString: @"NSTextField"])
{
newCell = [[NSTextFieldCell alloc] init];
className = [_classManager nonCustomSuperClassOf: name];
}
// copy everything from the old cell...
[newCell setFont: [cell font]];
[newCell setEnabled: [cell isEnabled]];
[newCell setEditable: [cell isEditable]];
[newCell setImportsGraphics: [cell importsGraphics]];
[newCell setShowsFirstResponder: [cell showsFirstResponder]];
[newCell setRefusesFirstResponder: [cell refusesFirstResponder]];
[newCell setBordered: [cell isBordered]];
[newCell setBezeled: [cell isBezeled]];
[newCell setScrollable: [cell isScrollable]];
[newCell setSelectable: [cell isSelectable]];
[newCell setState: [cell state]];
if(className != nil)
{
Class cls = NSClassFromString(className);
if(cls != nil)
{
NSCell *cell = [obj cell];
Class cellClass = [cls cellClass];
NSCell *newCell = [[cellClass alloc] init];
BOOL drawsBackground = [object drawsBackground];
// set attributes of textfield.
[object setCell: newCell];
[object setDrawsBackground: drawsBackground];
// copy everything from the old cell...
if([newCell respondsToSelector: @selector(setFont:)])
[newCell setFont: [cell font]];
if([newCell respondsToSelector: @selector(setEnabled:)])
[newCell setEnabled: [cell isEnabled]];
if([newCell respondsToSelector: @selector(setEditable:)])
[newCell setEditable: [cell isEditable]];
if([newCell respondsToSelector: @selector(setImportsGraphics:)])
[newCell setImportsGraphics: [cell importsGraphics]];
if([newCell respondsToSelector: @selector(setShowsFirstResponder:)])
[newCell setShowsFirstResponder: [cell showsFirstResponder]];
if([newCell respondsToSelector: @selector(setRefusesFirstResponder:)])
[newCell setRefusesFirstResponder: [cell refusesFirstResponder]];
if([newCell respondsToSelector: @selector(setBordered:)])
[newCell setBordered: [cell isBordered]];
if([newCell respondsToSelector: @selector(setBezeled:)])
[newCell setBezeled: [cell isBezeled]];
if([newCell respondsToSelector: @selector(setScrollable:)])
[newCell setScrollable: [cell isScrollable]];
if([newCell respondsToSelector: @selector(setSelectable:)])
[newCell setSelectable: [cell isSelectable]];
if([newCell respondsToSelector: @selector(setState:)])
[newCell setState: [cell state]];
// set attributes of textfield.
[object setCell: newCell];
if([newCell respondsToSelector: @selector(setDrawsBackground:)])
[object setDrawsBackground: drawsBackground];
[object setNeedsDisplay: YES];
}
}
}
}
- (void) select: (id)sender
{
NSCell *cell = [browser selectedCellInColumn: 0];

View file

@ -86,6 +86,25 @@ static BOOL _illegalClassSubstitution = NO;
+ (BOOL) canSubstituteForClass: (Class)origClass
{
if(self == origClass)
{
return YES;
}
else if([self isSubclassOfClass: origClass])
{
Class cls = self;
while(cls != nil && cls != origClass)
{
if(GSGetMethod(cls, @selector(initWithCoder:), YES, NO) != NULL &&
GSGetMethod(cls, @selector(encodeWithCoder:), YES, NO) != NULL)
{
return NO;
}
cls = GSObjCSuper(cls); // get super class
}
return YES;
}
return NO;
}
@end

View file

@ -31,6 +31,7 @@
#define VSTR(str) ({id _str = str; (_str) ? _str : @"";})
/* This is so that the NSSecureTextField will show in the custom class inspector */
/*
@implementation NSSecureTextField (IBObjectAdditions)
+ (BOOL) canSubstituteForClass: (Class)origClass
{
@ -42,6 +43,7 @@
return NO;
}
@end
*/
/*----------------------------------------------------------------------------
* NSBox

View file

@ -37,7 +37,6 @@
BOOL _gormAllowsColumnSelection;
BOOL _gormAllowsMultipleSelection;
BOOL _gormAllowsEmptySelection;
// NSColor *_savedColor;
}
- (void) setGormDelegate: (id)anObject;
@ -51,10 +50,6 @@
- (BOOL) gormAllowsEmptySelection;
- (void) setGormAllowsColumnSelection: (BOOL)flag;
- (BOOL) gormAllowsColumnSelection;
// preserve the color during selection...
//- (void) select;
//- (void) unselect;
@end
#endif

View file

@ -192,7 +192,6 @@ static id _sharedDataSource = nil;
self = [super initWithFrame: aRect];
[super setDataSource: [GormNSOutlineView sharedDataSource]];
_gormDataSource = nil;
// ASSIGN(_savedColor,[NSColor controlBackgroundColor]);
return self;
}
@ -225,18 +224,22 @@ static id _sharedDataSource = nil;
{
id oldDelegate;
int oldNumberOfRows;
// set real values...
_allowsColumnReordering = _gormAllowsColumnReordering;
_allowsColumnResizing = _gormAllowsColumnResizing;
_allowsColumnSelection = _gormAllowsColumnSelection;
_allowsMultipleSelection = _gormAllowsMultipleSelection;
_allowsEmptySelection = _gormAllowsEmptySelection;
_dataSource = _gormDataSource;
oldDelegate = _delegate;
_delegate = _gormDelegate;
oldNumberOfRows = _numberOfRows;
_numberOfRows = 0;
[super encodeWithCoder: aCoder];
// set fake values back...
_numberOfRows = oldNumberOfRows;
_allowsColumnReordering = YES;
_allowsColumnResizing = YES;
@ -251,8 +254,8 @@ static id _sharedDataSource = nil;
- (id) initWithCoder: (NSCoder*) aCoder
{
self = [super initWithCoder: aCoder];
[super setDataSource: [GormNSOutlineView sharedDataSource]];
[super setDataSource: [GormNSOutlineView sharedDataSource]];
_gormAllowsColumnReordering = _allowsColumnReordering;
_gormAllowsColumnResizing = _allowsColumnResizing;
_gormAllowsColumnSelection = _allowsColumnSelection;
@ -260,15 +263,13 @@ static id _sharedDataSource = nil;
_gormAllowsEmptySelection = _allowsEmptySelection;
_gormDelegate = _delegate;
_delegate = nil;
// ASSIGN(_savedColor, [self backgroundColor]);
return self;
}
- (void) dealloc
- (void) awakeFromNib
{
// RELEASE(_savedColor);
[super dealloc];
[super setDataSource: [GormNSOutlineView sharedDataSource]];
}
- (void) setGormAllowsColumnReordering: (BOOL)flag
@ -325,23 +326,4 @@ static id _sharedDataSource = nil;
{
return @"NSOutlineView";
}
/*
- (void) setBackgroundColor: (NSColor *)color
{
[super setBackgroundColor: color];
ASSIGN(_savedColor, color);
}
- (void) select
{
[super setBackgroundColor: [NSColor whiteColor]];
}
- (void) unselect
{
[super setBackgroundColor: _savedColor];
[self deselectAll: self];
}
*/
@end

View file

@ -37,7 +37,6 @@
BOOL _gormAllowsColumnSelection;
BOOL _gormAllowsMultipleSelection;
BOOL _gormAllowsEmptySelection;
// NSColor *_savedColor;
}
- (void) setGormDelegate: (id)anObject;
@ -51,12 +50,6 @@
- (BOOL) gormAllowsEmptySelection;
- (void) setGormAllowsColumnSelection: (BOOL)flag;
- (BOOL) gormAllowsColumnSelection;
// preserve the color during selection...
/*
- (void) select;
- (void) unselect;
*/
@end
#endif

View file

@ -144,21 +144,21 @@ static id _sharedDataSource = nil;
- (void)encodeWithCoder: (NSCoder*) aCoder
{
id oldDelegate;
// set actual values...
_allowsColumnReordering = _gormAllowsColumnReordering;
_allowsColumnResizing = _gormAllowsColumnResizing;
_allowsColumnSelection = _gormAllowsColumnSelection;
_allowsMultipleSelection = _gormAllowsMultipleSelection;
_allowsEmptySelection = _gormAllowsEmptySelection;
if([(id<IB>)NSApp isTestingInterface] == NO)
{
_dataSource = _gormDataSource;
oldDelegate = _delegate;
_delegate = _gormDelegate;
}
_dataSource = _gormDataSource;
oldDelegate = _delegate;
_delegate = _gormDelegate;
_numberOfRows = 0;
[super encodeWithCoder: aCoder];
// reset fake values...
_numberOfRows = 10;
_allowsColumnReordering = YES;
_allowsColumnResizing = YES;
@ -166,18 +166,15 @@ static id _sharedDataSource = nil;
_allowsMultipleSelection = NO;
_allowsEmptySelection = YES;
if([(id<IB>)NSApp isTestingInterface] == NO)
{
_delegate = oldDelegate;
_dataSource = _sharedDataSource;
}
_delegate = oldDelegate;
_dataSource = _sharedDataSource;
}
- (id) initWithCoder: (NSCoder*) aCoder
{
self = [super initWithCoder: aCoder];
[super setDataSource: [GormNSTableView sharedDataSource]];
[super setDataSource: [GormNSTableView sharedDataSource]];
_gormAllowsColumnReordering = _allowsColumnReordering;
_gormAllowsColumnResizing = _allowsColumnResizing;
_gormAllowsColumnSelection = _allowsColumnSelection;
@ -185,15 +182,13 @@ static id _sharedDataSource = nil;
_gormAllowsEmptySelection = _allowsEmptySelection;
_gormDelegate = _delegate;
_delegate = nil;
// ASSIGN(_savedColor, [self backgroundColor]);
return self;
}
- (void) dealloc
- (void) awakeFromNib
{
// RELEASE(_savedColor);
[super dealloc];
[super setDataSource: [GormNSTableView sharedDataSource]];
}
- (void) setGormAllowsColumnReordering: (BOOL)flag
@ -250,23 +245,4 @@ static id _sharedDataSource = nil;
{
return @"NSTableView";
}
/*
- (void) setBackgroundColor: (NSColor *)color
{
[super setBackgroundColor: color];
ASSIGN(_savedColor, color);
}
- (void) select
{
[super setBackgroundColor: [NSColor whiteColor]];
}
- (void) unselect
{
[super setBackgroundColor: _savedColor];
[self deselectAll: self];
}
*/
@end