
/*
	NSView: Set and get a view's single subview
	Original Source: <http://cocoa.karelia.com/AppKit_Categories/NSView__Set_and_get.m>
	(See copyright notice at <http://cocoa.karelia.com>)
*/

/*"	Set inView to be the subview of self.  If there is currently no subview, it is impossible to properly size the subview to fit within the subview.
"*/

- (void) setSubview:(NSView *)inView
{
	NSArray *subviews = [self subviews];

	// Replace or insert subview if not the right one already
	if (0 == [subviews count])
	{
		[self addSubview:inView];		// ANY WAY TO AUTO-RESIZE IT?
	}
	else if ([subviews objectAtIndex:0] != inView)
	{
		NSView *oldSubview = [subviews objectAtIndex:0];
		NSRect frame = [oldSubview frame];
		[oldSubview removeFromSuperview];
		[inView setFrame:frame];
		[self addSubview:inView];
	}
}

/*"	Return the single (or first) subview of self.
"*/

- (id) subview
{
	id result = nil;
	NSArray *subviews = [self subviews];
	if ([subviews count])
	{
		result = [subviews objectAtIndex:0];
	}
	return result;
}