/* DockHandleView.m created by fred on Wed 22-Sep-1999 */

#import "DockHandleView.h"
#import "DockWindow.h"	//	Stupid

@implementation DockHandleView

- initWithFrame:(NSRect)aFrame
{	[super initWithFrame:aFrame];
	return self;
}

//	----------------------------------------------------------------------------

- (void)dealloc
{	[super dealloc];
}

@end

//	----------------------------------------------------------------------------

@implementation DockHandleView(NSResponder_Overrides)

- (void)mouseDown:(NSEvent *)anEvent
{	BOOL thefShouldDrag = YES;

	itsfHighlighted = YES;
	[self display];

	if ([anEvent clickCount]>=2)
	{		//	This collapses the dock
		[self doCommandBySelector:@selector(flipCollapse:)];

			//	Now, we check if the mouse is still in the view (in which case, we drag). This enable to double-clic and drag, without releasing the mouse.
		if (![self window] || !NSPointInRect( [self convertPoint:[anEvent locationInWindow] fromView:nil], [self bounds] ))
			thefShouldDrag = NO;
	}

	if (thefShouldDrag)
		[(DockWindow *)[self window] dragWindowFromEvent:anEvent view:self];

	itsfHighlighted = NO;
	[self display];
}

@end

//	----------------------------------------------------------------------------

@implementation DockHandleView(NSView_Overrides)

- (void)drawRect:(NSRect)aRect
{
	static NSRectEdge theSides[] = { NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge };
	static float theGrays[sizeof( theSides )/sizeof( theSides[0] )] = { 0, 0, 0, 0, 1, 0.333, 0.333, 1 };

	if (!itsfHighlighted)
	{	[[NSColor colorWithCalibratedWhite:0.5 alpha:1.0] set];
	}
	else
	{	[[NSColor colorWithCalibratedWhite:0.25 alpha:1.0] set];
	}

	NSRectFill( aRect );

	NSDrawTiledRects( [self bounds], aRect, theSides, theGrays, sizeof( theSides )/sizeof( theSides[0] ));
}

//	----------------------------------------------------------------------------

- (BOOL)acceptsFirstMouse:(NSEvent *)anEvent
{	return YES;
}

@end
