135 lines
3.4 KiB
Objective-C
135 lines
3.4 KiB
Objective-C
|
|
#import "EnvWindow.h"
|
|
#import "VScheme.h"
|
|
|
|
@implementation EnvWindow
|
|
|
|
#define WIDTH 300
|
|
#define HEIGHT 200
|
|
|
|
static int count = 0;
|
|
- initWithEnv:(Environment *)env
|
|
{
|
|
NSWindow *window;
|
|
Environment *layer; int lind;
|
|
NSRect scrollViewRect = {{0, 0}, {WIDTH, HEIGHT}};
|
|
NSRect winRect =
|
|
{{250+(count%12)*24, 100+(count%12)*24}, {WIDTH, HEIGHT}};
|
|
NSRect textRect;
|
|
unsigned int style = NSTitledWindowMask | NSClosableWindowMask |
|
|
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
|
NSString *title =
|
|
[NSString stringWithFormat:@"Scheme Env. # %d", ++count];
|
|
|
|
length = [env chainLength]; current=length-1;
|
|
forms = NSZoneMalloc([self zone], length*sizeof(id));
|
|
|
|
for(lind=length-1, layer = env; lind>=0; lind--){
|
|
NSMutableDictionary *data = [layer data];
|
|
NSMutableArray *keys;
|
|
NSEnumerator *en;
|
|
id key, form;
|
|
|
|
keys = [NSMutableArray arrayWithCapacity:1];
|
|
[keys setArray:[data allKeys]];
|
|
[keys sortUsingSelector:@selector(compare:)];
|
|
|
|
en = [keys objectEnumerator];
|
|
|
|
|
|
forms[lind] = form =
|
|
[[NSForm alloc] initWithFrame:scrollViewRect];
|
|
while((key = [en nextObject])!=nil){
|
|
id obj = [data objectForKey:key];
|
|
id ctitle = [NSString stringWithFormat:@" %@ ", key];
|
|
id cell = [form addEntry:ctitle];
|
|
|
|
[cell setEditable:NO];
|
|
[cell setEnabled:NO];
|
|
[cell setStringValue:[VScheme valToString:obj]];
|
|
}
|
|
|
|
[form setEntryWidth:WIDTH];
|
|
[form setAutosizesCells:YES];
|
|
[form setAutoresizingMask:NSViewWidthSizable];
|
|
|
|
// [form retain];
|
|
|
|
layer = [layer parent];
|
|
}
|
|
|
|
[self initWithContentRect:winRect
|
|
styleMask:style
|
|
backing:NSBackingStoreRetained
|
|
defer:NO];
|
|
[self setMinSize:NSMakeSize(WIDTH, HEIGHT)];
|
|
[self setReleasedWhenClosed:YES];
|
|
|
|
scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect];
|
|
[scrollView setHasHorizontalScroller:YES];
|
|
[scrollView setHasVerticalScroller:YES];
|
|
[scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
|
[[scrollView contentView] setAutoresizingMask: NSViewHeightSizable
|
|
| NSViewWidthSizable];
|
|
[[scrollView contentView] setAutoresizesSubviews:YES];
|
|
|
|
[scrollView setDocumentView:forms[current]];
|
|
|
|
[self setContentView:scrollView];
|
|
// RELEASE(scrollView);
|
|
|
|
[self setTitle:title];
|
|
[self display];
|
|
[self makeKeyAndOrderFront:nil];
|
|
|
|
return self;
|
|
}
|
|
|
|
- up:(id)sender
|
|
{
|
|
if(!current){
|
|
NSBeep();
|
|
}
|
|
else{
|
|
NSRect bounds = [forms[current] bounds];
|
|
current--;
|
|
[forms[current] setEntryWidth:bounds.size.width];
|
|
[scrollView setDocumentView:forms[current]];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- down:(id)sender
|
|
{
|
|
if(current==length-1){
|
|
NSBeep();
|
|
}
|
|
else{
|
|
NSRect bounds = [forms[current] bounds];
|
|
current++;
|
|
[forms[current] setEntryWidth:bounds.size.width];
|
|
[scrollView setDocumentView:forms[current]];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- releaseForms
|
|
{
|
|
int ind;
|
|
|
|
[scrollView setDocumentView:nil];
|
|
[scrollView release];
|
|
|
|
for(ind=0; ind<length; ind++){
|
|
// NSLog(@"%@ %d %d\n", self, ind, [forms[ind] retainCount]);
|
|
[forms[ind] release];
|
|
}
|
|
|
|
NSZoneFree([self zone], forms);
|
|
return self;
|
|
}
|
|
@end
|
|
|