mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-23 19:51:00 +00:00
Add code to handle generic objects
This commit is contained in:
parent
e15fcb380c
commit
bb0f192ae2
1 changed files with 257 additions and 50 deletions
|
@ -41,6 +41,8 @@
|
||||||
#import <AppKit/NSButton.h>
|
#import <AppKit/NSButton.h>
|
||||||
#import <AppKit/NSTextField.h>
|
#import <AppKit/NSTextField.h>
|
||||||
#import <AppKit/NSBox.h>
|
#import <AppKit/NSBox.h>
|
||||||
|
#import <AppKit/NSTableView.h>
|
||||||
|
#import <AppKit/NSOutlineView.h>
|
||||||
|
|
||||||
#import <GNUstepBase/GSObjCRuntime.h>
|
#import <GNUstepBase/GSObjCRuntime.h>
|
||||||
|
|
||||||
|
@ -218,6 +220,10 @@ static NSUInteger _count = INT_MAX;
|
||||||
- (void) _collectObjectsFromObject: (id)obj
|
- (void) _collectObjectsFromObject: (id)obj
|
||||||
withNode: (NSXMLElement *)node;
|
withNode: (NSXMLElement *)node;
|
||||||
|
|
||||||
|
- (void) _collectObjectsFromObject: (id)obj
|
||||||
|
ForKey: (NSString *)keyName
|
||||||
|
withNode: (NSXMLElement *)node;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -251,6 +257,19 @@ static NSUInteger _count = INT_MAX;
|
||||||
@"BOOL", @"isBordered",
|
@"BOOL", @"isBordered",
|
||||||
@"NSUInteger", @"autoresizingMask",
|
@"NSUInteger", @"autoresizingMask",
|
||||||
@"NSUInteger", @"titlePosition",
|
@"NSUInteger", @"titlePosition",
|
||||||
|
@"BOOL", @"isEditable", // NSTableColumn
|
||||||
|
@"BOOL", @"isResizable",
|
||||||
|
@"BOOL", @"isHidden",
|
||||||
|
@"CGFloat", @"minWidth",
|
||||||
|
@"CGFloat", @"maxWidth",
|
||||||
|
@"CGFloat", @"width",
|
||||||
|
@"NSString", @"headerToolTip",
|
||||||
|
@"NSString", @"identifier",
|
||||||
|
@"NSCell", @"headerCell",
|
||||||
|
@"NSCell", @"dataCell",
|
||||||
|
@"NSView", @"headerView",
|
||||||
|
@"CGFloat", @"rowHeight",
|
||||||
|
@"NSFont", @"font",
|
||||||
nil];
|
nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,11 +498,15 @@ static NSUInteger _count = INT_MAX;
|
||||||
NSMutableArray *result = [NSMutableArray array];
|
NSMutableArray *result = [NSMutableArray array];
|
||||||
|
|
||||||
while ((name = [en nextObject]) != nil)
|
while ((name = [en nextObject]) != nil)
|
||||||
|
{
|
||||||
|
if ([name isEqualToString: @"set"] == NO) // this is the [NSFont set] method... skip...
|
||||||
{
|
{
|
||||||
NSString *substring = [name substringToIndex: 3];
|
NSString *substring = [name substringToIndex: 3];
|
||||||
if ([substring isEqualToString: @"set"])
|
if ([substring isEqualToString: @"set"])
|
||||||
{
|
{
|
||||||
NSString *os = [[name substringFromIndex: 3] stringByReplacingOccurrencesOfString: @":" withString: @""];
|
NSString *os = [[name substringFromIndex: 3]
|
||||||
|
stringByReplacingOccurrencesOfString: @":"
|
||||||
|
withString: @""];
|
||||||
NSString *s = [os lowercaseFirstCharacter];
|
NSString *s = [os lowercaseFirstCharacter];
|
||||||
NSString *iss = [NSString stringWithFormat: @"is%@", os];
|
NSString *iss = [NSString stringWithFormat: @"is%@", os];
|
||||||
|
|
||||||
|
@ -514,6 +537,7 @@ static NSUInteger _count = INT_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -658,7 +682,7 @@ static NSUInteger _count = INT_MAX;
|
||||||
- (void) _addBezelStyleForObject: (id)obj
|
- (void) _addBezelStyleForObject: (id)obj
|
||||||
toElement: (NSXMLElement *)elem
|
toElement: (NSXMLElement *)elem
|
||||||
{
|
{
|
||||||
NSString *result = @"rounded";
|
NSString *result = nil;
|
||||||
NSXMLNode *attr = nil;
|
NSXMLNode *attr = nil;
|
||||||
|
|
||||||
if ([obj isKindOfClass: [NSButton class]])
|
if ([obj isKindOfClass: [NSButton class]])
|
||||||
|
@ -702,8 +726,11 @@ static NSUInteger _count = INT_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result != nil)
|
||||||
|
{
|
||||||
attr = [NSXMLNode attributeWithName: @"bezelStyle" stringValue: result];
|
attr = [NSXMLNode attributeWithName: @"bezelStyle" stringValue: result];
|
||||||
[elem addAttribute: attr];
|
[elem addAttribute: attr];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _addBorderStyle: (BOOL)bordered toElement: (NSXMLElement *)elem
|
- (void) _addBorderStyle: (BOOL)bordered toElement: (NSXMLElement *)elem
|
||||||
|
@ -774,13 +801,84 @@ static NSUInteger _count = INT_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _addTableColumns: (NSArray *)cols toElement: (NSXMLElement *)elem
|
||||||
|
{
|
||||||
|
if ([cols count] > 0)
|
||||||
|
{
|
||||||
|
NSXMLElement *tblColElem = [NSXMLNode elementWithName: @"tableColumns"];
|
||||||
|
NSEnumerator *en = [cols objectEnumerator];
|
||||||
|
id col = nil;
|
||||||
|
|
||||||
|
// NSLog(@"cols = %@", cols);
|
||||||
|
while ((col = [en nextObject]) != nil)
|
||||||
|
{
|
||||||
|
[self _collectObjectsFromObject: col
|
||||||
|
withNode: tblColElem];
|
||||||
|
}
|
||||||
|
|
||||||
|
[elem addChild: tblColElem];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _addBoolean: (BOOL)flag withName: (NSString *)name toElement: (NSXMLElement *)elem
|
||||||
|
{
|
||||||
|
if (flag == YES)
|
||||||
|
{
|
||||||
|
NSXMLNode *attr = [NSXMLNode attributeWithName: name
|
||||||
|
stringValue: @"YES"];
|
||||||
|
[elem addAttribute: attr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _addFloat: (CGFloat)f withName: (NSString *)name toElement: (NSXMLElement *)elem
|
||||||
|
{
|
||||||
|
NSString *val = [NSString stringWithFormat: @"%4.1f",f];
|
||||||
|
NSXMLNode *attr = [NSXMLNode attributeWithName: name
|
||||||
|
stringValue: val];
|
||||||
|
[elem addAttribute: attr];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _addString: (NSString *)val withName: (NSString *)name toElement: (NSXMLElement *)elem
|
||||||
|
{
|
||||||
|
if (val != nil && [val isEqualToString: @""] == NO)
|
||||||
|
{
|
||||||
|
NSXMLNode *attr = [NSXMLNode attributeWithName: name
|
||||||
|
stringValue: val];
|
||||||
|
[elem addAttribute: attr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) _addProperty: (NSString *)name
|
- (void) _addProperty: (NSString *)name
|
||||||
withType: (NSString *)type
|
withType: (NSString *)type
|
||||||
toElem: (NSXMLElement *)elem
|
toElem: (NSXMLElement *)elem
|
||||||
fromObject: (id)obj
|
fromObject: (id)obj
|
||||||
{
|
{
|
||||||
NSDebugLog(@"%@ -> %@: %@", name, type, elem);
|
Class clz = NSClassFromString(type);
|
||||||
if ([name isEqualToString: @"frame"])
|
if (clz != nil) // type is a class
|
||||||
|
{
|
||||||
|
if (clz != [NSString class])
|
||||||
|
{
|
||||||
|
SEL s = NSSelectorFromString(name);
|
||||||
|
if (s != NULL)
|
||||||
|
{
|
||||||
|
if ([obj respondsToSelector: s])
|
||||||
|
{
|
||||||
|
id o = [obj performSelector: s];
|
||||||
|
NSString *ident = [self _createIdentifierForObject: o];
|
||||||
|
NSXMLNode *attr = [NSXMLNode attributeWithName: name
|
||||||
|
stringValue: ident];
|
||||||
|
|
||||||
|
[elem addAttribute: attr];
|
||||||
|
|
||||||
|
[self _collectObjectsFromObject: o
|
||||||
|
forKey: name
|
||||||
|
withNode: elem];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"frame"])
|
||||||
{
|
{
|
||||||
NSRect f = [obj frame];
|
NSRect f = [obj frame];
|
||||||
[self _addRect: f toElement: elem withName: name];
|
[self _addRect: f toElement: elem withName: name];
|
||||||
|
@ -821,7 +919,7 @@ static NSUInteger _count = INT_MAX;
|
||||||
else if ([name isEqualToString: @"isBordered"] && [obj respondsToSelector: @selector(cell)] == NO)
|
else if ([name isEqualToString: @"isBordered"] && [obj respondsToSelector: @selector(cell)] == NO)
|
||||||
{
|
{
|
||||||
BOOL bordered = [obj isBordered];
|
BOOL bordered = [obj isBordered];
|
||||||
NSLog(@"Handling isBordered...");
|
NSDebugLog(@"Handling isBordered...");
|
||||||
[self _addBorderStyle: bordered
|
[self _addBorderStyle: bordered
|
||||||
toElement: elem];
|
toElement: elem];
|
||||||
}
|
}
|
||||||
|
@ -831,12 +929,95 @@ static NSUInteger _count = INT_MAX;
|
||||||
[self _addTitlePosition: p
|
[self _addTitlePosition: p
|
||||||
toElement: elem];
|
toElement: elem];
|
||||||
}
|
}
|
||||||
else if ([name isEqualToString: @"cell"])
|
else if ([name isEqualToString: @"isHidden"])
|
||||||
{
|
{
|
||||||
NSDebugLog(@"cell = %@", [obj cell]);
|
BOOL f = [obj isHidden];
|
||||||
[self _collectObjectsFromObject: [obj cell]
|
[self _addBoolean: f
|
||||||
|
withName: @"hidden"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"isResizable"])
|
||||||
|
{
|
||||||
|
BOOL f = [obj isResizable];
|
||||||
|
[self _addBoolean: f
|
||||||
|
withName: @"resizable"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"isEditable"])
|
||||||
|
{
|
||||||
|
BOOL f = [obj isEditable];
|
||||||
|
[self _addBoolean: f
|
||||||
|
withName: @"editable"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"minWidth"])
|
||||||
|
{
|
||||||
|
CGFloat f = [obj minWidth];
|
||||||
|
[self _addFloat: f
|
||||||
|
withName: @"minWidth"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"maxWidth"])
|
||||||
|
{
|
||||||
|
CGFloat f = [obj maxWidth];
|
||||||
|
[self _addFloat: f
|
||||||
|
withName: @"maxWidth"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"width"])
|
||||||
|
{
|
||||||
|
CGFloat f = [obj width];
|
||||||
|
[self _addFloat: f
|
||||||
|
withName: @"width"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"rowHeight"])
|
||||||
|
{
|
||||||
|
CGFloat f = [obj rowHeight];
|
||||||
|
[self _addFloat: f
|
||||||
|
withName: @"rowHeight"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"headerToolTip"])
|
||||||
|
{
|
||||||
|
NSString *val = [obj headerToolTip];
|
||||||
|
[self _addString: val
|
||||||
|
withName: @"headerToolTip"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"identifier"])
|
||||||
|
{
|
||||||
|
NSString *val = [obj identifier];
|
||||||
|
[self _addString: val
|
||||||
|
withName: @"identifier"
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
else if ([name isEqualToString: @"dataCell"])
|
||||||
|
{
|
||||||
|
[self _collectObjectsFromObject: [obj dataCell]
|
||||||
|
forKey: name
|
||||||
withNode: elem];
|
withNode: elem];
|
||||||
}
|
}
|
||||||
|
else if ([name isEqualToString: @"headerCell"])
|
||||||
|
{
|
||||||
|
[self _collectObjectsFromObject: [obj headerCell]
|
||||||
|
forKey: name
|
||||||
|
withNode: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"headerView"])
|
||||||
|
{
|
||||||
|
[self _collectObjectsFromObject: [obj headerView]
|
||||||
|
forKey: name
|
||||||
|
withNode: elem];
|
||||||
|
}
|
||||||
|
else if ([name isEqualToString: @"cell"])
|
||||||
|
{
|
||||||
|
[self _collectObjectsFromObject: [obj cell]
|
||||||
|
forKey: name
|
||||||
|
withNode: elem];
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _addAllProperties: (NSXMLElement *)elem fromObject: (id)obj
|
- (void) _addAllProperties: (NSXMLElement *)elem fromObject: (id)obj
|
||||||
|
@ -897,7 +1078,7 @@ static NSUInteger _count = INT_MAX;
|
||||||
connectors =[_gormDocument connectorsForSource: obj
|
connectors =[_gormDocument connectorsForSource: obj
|
||||||
ofClass: [NSNibOutletConnector class]];
|
ofClass: [NSNibOutletConnector class]];
|
||||||
|
|
||||||
NSLog(@"outlet connectors = %@, for obj = %@", connectors, obj);
|
NSDebugLog(@"outlet connectors = %@, for obj = %@", connectors, obj);
|
||||||
|
|
||||||
if ([connectors count] > 0)
|
if ([connectors count] > 0)
|
||||||
{
|
{
|
||||||
|
@ -932,7 +1113,8 @@ static NSUInteger _count = INT_MAX;
|
||||||
|
|
||||||
// This method recursively navigates the entire object tree and emits XML
|
// This method recursively navigates the entire object tree and emits XML
|
||||||
- (void) _collectObjectsFromObject: (id)obj
|
- (void) _collectObjectsFromObject: (id)obj
|
||||||
withNode: (NSXMLElement *)node
|
forKey: (NSString *)keyName
|
||||||
|
withNode: (NSXMLElement *)parentNode
|
||||||
{
|
{
|
||||||
NSString *ident = [self _createIdentifierForObject: obj];
|
NSString *ident = [self _createIdentifierForObject: obj];
|
||||||
|
|
||||||
|
@ -952,6 +1134,13 @@ static NSUInteger _count = INT_MAX;
|
||||||
[elem addAttribute: attr];
|
[elem addAttribute: attr];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add key to elem...
|
||||||
|
if (keyName != nil && [keyName isEqualToString: @""] == NO)
|
||||||
|
{
|
||||||
|
attr = [NSXMLNode attributeWithName: @"key" stringValue: keyName];
|
||||||
|
[elem addAttribute: attr];
|
||||||
|
}
|
||||||
|
|
||||||
if ([obj isKindOfClass: [GormObjectProxy class]] ||
|
if ([obj isKindOfClass: [GormObjectProxy class]] ||
|
||||||
[obj respondsToSelector: @selector(className)])
|
[obj respondsToSelector: @selector(className)])
|
||||||
{
|
{
|
||||||
|
@ -970,7 +1159,7 @@ static NSUInteger _count = INT_MAX;
|
||||||
[self _addAllProperties: elem fromObject: obj];
|
[self _addAllProperties: elem fromObject: obj];
|
||||||
if ([name isEqualToString: @"NSMenu"] == NO)
|
if ([name isEqualToString: @"NSMenu"] == NO)
|
||||||
{
|
{
|
||||||
[node addChild: elem];
|
[parentNode addChild: elem];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the object responds to "title" get that and add it to the XML
|
// If the object responds to "title" get that and add it to the XML
|
||||||
|
@ -984,13 +1173,6 @@ static NSUInteger _count = INT_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([obj isKindOfClass: [NSCell class]])
|
|
||||||
{
|
|
||||||
NSXMLNode *attr = [NSXMLNode attributeWithName: @"key"
|
|
||||||
stringValue: @"cell"];
|
|
||||||
[elem addAttribute: attr];
|
|
||||||
}
|
|
||||||
|
|
||||||
// For each different class, recurse through the structure as needed.
|
// For each different class, recurse through the structure as needed.
|
||||||
if ([obj isKindOfClass: [NSMenu class]])
|
if ([obj isKindOfClass: [NSMenu class]])
|
||||||
{
|
{
|
||||||
|
@ -1025,7 +1207,7 @@ static NSUInteger _count = INT_MAX;
|
||||||
|
|
||||||
[mainMenuItem addChild: elem]; // Now add the node, since we have inserted the proper system menu
|
[mainMenuItem addChild: elem]; // Now add the node, since we have inserted the proper system menu
|
||||||
|
|
||||||
[node addChild: mainMenuElem];
|
[parentNode addChild: mainMenuElem];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add submenu attribute...
|
// Add submenu attribute...
|
||||||
|
@ -1090,6 +1272,12 @@ static NSUInteger _count = INT_MAX;
|
||||||
[elem addChild: menuElem]; // Add to parent element...
|
[elem addChild: menuElem]; // Add to parent element...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([obj isKindOfClass: [NSTableHeaderView class]])
|
||||||
|
{
|
||||||
|
NSXMLNode *attr = [NSXMLNode attributeWithName: @"key" stringValue: @"headerView"];
|
||||||
|
[elem addAttribute: attr];
|
||||||
|
}
|
||||||
|
|
||||||
if ([obj isKindOfClass: [NSWindow class]])
|
if ([obj isKindOfClass: [NSWindow class]])
|
||||||
{
|
{
|
||||||
NSRect s = [[NSScreen mainScreen] frame];
|
NSRect s = [[NSScreen mainScreen] frame];
|
||||||
|
@ -1131,6 +1319,9 @@ static NSUInteger _count = INT_MAX;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSArray *subviews = [obj subviews];
|
NSArray *subviews = [obj subviews];
|
||||||
|
|
||||||
|
if ([subviews count] > 0)
|
||||||
|
{
|
||||||
NSEnumerator *en = [subviews objectEnumerator];
|
NSEnumerator *en = [subviews objectEnumerator];
|
||||||
id v = nil;
|
id v = nil;
|
||||||
NSXMLElement *subviewsElement = [NSXMLNode elementWithName: @"subviews"];
|
NSXMLElement *subviewsElement = [NSXMLNode elementWithName: @"subviews"];
|
||||||
|
@ -1144,8 +1335,24 @@ static NSUInteger _count = INT_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([obj respondsToSelector: @selector(tableColumns)])
|
||||||
|
{
|
||||||
|
[self _addTableColumns: [obj tableColumns]
|
||||||
|
toElement: elem];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _collectObjectsFromObject: (id)obj
|
||||||
|
withNode: (NSXMLElement *)node
|
||||||
|
{
|
||||||
|
[self _collectObjectsFromObject: obj
|
||||||
|
forKey: nil
|
||||||
|
withNode: node];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) _buildXIBDocumentWithParentNode: (NSXMLElement *)parentNode
|
- (void) _buildXIBDocumentWithParentNode: (NSXMLElement *)parentNode
|
||||||
{
|
{
|
||||||
NSEnumerator *en = [[_gormDocument topLevelObjects] objectEnumerator];
|
NSEnumerator *en = [[_gormDocument topLevelObjects] objectEnumerator];
|
||||||
|
|
Loading…
Reference in a new issue