
#import "DemoView.h"
#import "EDBOutlet.h"
#import "EDBConnector.h"

@implementation DemoView

- initFrame:(const NXRect *)frameRect
{
	EDBOutlet	*outlet;

	[super initFrame:frameRect];

	outlets = [[List alloc] initCount:4];
	outlet = [[EDBOutlet alloc] init];
	[outlet setOutletName:NXUniqueString("normalOutlet")];
	[outlet setIsTarget:NO];
	[outlet setMultiUse:NO];
	[outlets addObject:outlet];
	outlet = [[EDBOutlet alloc] init];
	[outlet setOutletName:NXUniqueString("multiUseOutlet")];
	[outlet setIsTarget:NO];
	[outlet setMultiUse:YES];
	[outlets addObject:outlet];
	outlet = [[EDBOutlet alloc] init];
	[outlet setOutletName:NXUniqueString("targetOutlet")];
	[outlet setIsTarget:YES];
	[outlet setMultiUse:NO];
	[outlets addObject:outlet];
	outlet = [[EDBOutlet alloc] init];
	[outlet setOutletName:NXUniqueString("mUseAndTarget")];
	[outlet setIsTarget:YES];
	[outlet setMultiUse:YES];
	[outlets addObject:outlet];

	return self;
}

- drawSelf:(const NXRect *)rect:(int)count
{
	NXRect	boundRect;

	[super drawSelf:rect:count];
	[self getBounds:&boundRect];
	PSsetgray(NX_WHITE);
	NXRectFill(&boundRect);
	PSsetgray(NX_BLACK);
	PSrectstroke(NX_X(&boundRect),NX_Y(&boundRect)+1,
				 NX_WIDTH(&boundRect)-1,NX_HEIGHT(&boundRect)-1);

	return self;
}

- read:(NXTypedStream *)stream
{
	[super read:stream];
	outlets = NXReadObject(stream);
	return self;
}

- write:(NXTypedStream *)stream
{
	[super write:stream];
	NXWriteObject(stream,outlets);
	return self;
}

- (const char *)getConnectInspectorClassName
{
	return "EDBConnectInspector";
}

- (List *)getOutlets
{
	return outlets;
}

- establishEDBConnection:connection		// called for outlets multiUseOutlet,
										// targetOutlet and
										// multiUseAndTargetOutlet, because
										// there is no corresponding method
										// setXxx:.
{
	printf("establishingConnection: outletName=%s, selName=%s, sequence=%hd\n",
		[connection outletName],[connection selName],[connection sequence]);
	// Here you could put [connection destination] into a list of destinations.
	// [connection sequence] allows you to perserve ordering.

	return self;
}

- setNormalOutlet:sender
{
	printf("Setting normal Outlet\n");
	return self;
}

@end
