/* Controller.m created by fred on Tue 21-Sep-1999 */

#import "Controller.h"

#import "DockHandleView.h"
#import "DockBackgroundView.h"

#define DOCK_ASPECT	24
#define W_BORDER		3
#define B_INTERSPACE	2
#define D_SIZE		10

@implementation Controller

#if 0

- (void)_sdAddApplication:(NSString *)aFullPath
{
/*
	NSImageView *theImageView = [[[NSImageView alloc] init] autorelease];

	[theImageView setImage:[self _sdMiniImageForFile:aFullPath]];
	[theImageView setFrame:NSMakeRect( itsLastX,2,DOCK_ASPECT,DOCK_ASPECT )];

	[[itsWindow contentView] addSubview:theImageView];
*/
	TileView *theButton = [[[TileView alloc] init] autorelease];

//	[theButton setImage:[self _sdMiniImageForFile:aFullPath]];
	[theButton setBordered:NO];
	[theButton setButtonType:NSMomentaryChangeButton];
	[theButton setFrame:NSMakeRect( itsLastX, W_BORDER, DOCK_ASPECT,DOCK_ASPECT )];

	[[itsWindow contentView] addSubview:theButton];
	[theButton setPath:aFullPath];
//	[[theButton cell] setRepresentedObject:aFullPath];
	[theButton setTarget:self];
	[theButton setAction:@selector(_sdLaunch:)];

	itsLastX += DOCK_ASPECT+B_INTERSPACE;
}

- (void)_sdAddApplications
{	itsWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect( 1, 1, (DOCK_ASPECT+B_INTERSPACE)*32-B_INTERSPACE+W_BORDER*2+D_SIZE, DOCK_ASPECT+ W_BORDER*2 ) styleMask:NSBorderlessWindowMask backing: NSBackingStoreBuffered defer:YES screen:[NSScreen mainScreen]];
	[itsWindow setContentView:[[[DockBackgroundView alloc] init] autorelease]];
	[itsWindow setLevel:NSStatusWindowLevel];

[itsWindow setDelegate:self];

	{	DockHandleView *theDragHandle;
		theDragHandle = [[[DockHandleView alloc] init] autorelease];
		[[itsWindow contentView] addSubview:theDragHandle];
			//	Left handle
		itsLastX = W_BORDER;
		[theDragHandle setFrame:NSMakeRect( NSMaxX( [[itsWindow contentView] bounds] ) - D_SIZE, 0, D_SIZE, NSHeight(  [[itsWindow contentView] bounds] ) ) ];
			//	Right handle
//	itsLastX = W_BORDER + D_SIZE;
//		[theDragHandle setFrame:NSMakeRect( 0, 0, D_SIZE, NSHeight(  [[itsWindow contentView] bounds] ) ) ];
	}

//	[itsWindow setFrame: display:NO];


{	int i;
	for (i=8;i!=32;i++)
		[self _sdAddApplication:nil];
}

	[itsWindow orderFront:self];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{	[self _sdAddApplications];
	NSLog( @"Done" );
}

	//	We should do a small animation there and in the next method
	//	(Copy window content in an offscreen buffer, and animate the collapse)
- (void)uncollapse:sender
{	itsfCollapsed = NO;
	[itsWindow setContentSize:NSMakeSize(  (DOCK_ASPECT+B_INTERSPACE)*32-B_INTERSPACE+W_BORDER*2+D_SIZE, DOCK_ASPECT+ W_BORDER*2 )];
}

- (void)collapse:sender
{	itsfCollapsed = YES;
	[itsWindow setContentSize:NSMakeSize(  D_SIZE, DOCK_ASPECT+ W_BORDER*2 )];
}

- (BOOL)isCollapsed
{	return itsfCollapsed;
}

- (void)flipCollapse:sender
{	NSLog( @"Collapse" );
	if ([self isCollapsed])
		[self uncollapse:sender];
	else
		[self collapse:sender];
}

#endif

@end

