
/* Generated by Interface Builder */

#import "StackView.h"
#import	<assert.h>
#import	<objc/List.h>
#import	<stdio.h>


@implementation StackView


+ newFrame:( const NXRect * )frameRect
{

	
	self				= [ super newFrame:frameRect ];
	overlapModeFlag		=
	reactiveCardsFlag	= NO;
	
	return self;
}


- setOverlap:( BOOL )flag
{

	overlapModeFlag = flag;
	
	return self;
}


- addCard:( CardView * )aCard :sender
{


	[ self addSubview:[ aCard setEventsEnabled:reactiveCardsFlag ]];

	return [ self _adjustCards ];
}


- removeCard:( CardView * )aCard :sender
{


	assert([ aCard isDescendantOf:self ]);
	[ aCard removeFromSuperview ];

	return [ self _adjustCards ];
}


- ( CardView * )topCard
{


	return [[ self subviews ] lastObject ];
}


- _adjustCards
{

	int		i;
	
	for( i = 0; i < [ subviews count ]; ++i ) {
		View	*aSubview = [ subviews objectAt:i ];
		NXRect	subviewBounds;
			
												// The displacement of the card from the top of this
												//	stack view is calculated by the cards position.  The
												//	top of the card is moved down 20 pixels from its
												//	predecessor on the stack.
		[ aSubview getBounds:&subviewBounds ];
		[ aSubview moveTo 
					:(( NX_WIDTH( &bounds ) - NX_WIDTH( &subviewBounds )) / 2 )
					:NX_HEIGHT( &bounds ) -  2 - ( i * ( overlapModeFlag ? 20 : 0 )) - NX_HEIGHT( &subviewBounds ) ];
	}

	return self;
}


- sendCard:( CardView * )aCard to:anObject
{

	assert([ aCard isDescendantOf:self ]);
	[ self removeCard:aCard		:self ];
	[ anObject addCard:aCard	:self ];
	
	return self;
}

	 
- sendAllCardsTo:anObject
{

	while([ subviews count ])
		[ self sendCard:[ subviews lastObject ] to:anObject ];
		
	return self;
}


- ( BOOL )subviewVisible:aView
{

	BOOL	retVal = YES;
	
	
	if( !overlapModeFlag )
		if([ subviews lastObject ] != aView )
			retVal = NO;
		
	return retVal;	
}


@end
