/* DockWindow.m created by fred on Sat 25-Sep-1999 */

#import "DockWindow.h"

@implementation DockWindow

- (NSPoint)snapOrigin:(NSPoint)anOrigin
{
//	anOrigin.x = 0;
	return anOrigin;
}

//	Would be better in a NSView category...
- (void)dragWindowFromEvent:(NSEvent *)anEvent view:(NSView *)aView
{	NSPoint theOrigin = [self convertBaseToScreen:[anEvent locationInWindow]];
	NSEvent *theEvent = anEvent;
	NSPoint theFrameOrigin = [self frame].origin;

	do
	{
//		Location in window is not a wise idea, because it is the location in window _at the time_ the event was generaged. The window may have moved since, as there may be several mouseDragged in the event queue
//		NSPoint theCurrentPoint = [self convertBaseToScreen:[theEvent locationInWindow]];

//		Taking the location outside of event stream is not nice, but does the trick
		NSPoint theCurrentPoint = [self convertBaseToScreen:[self mouseLocationOutsideOfEventStream]];

		NSPoint theTargetFrameOrigin = NSMakePoint( theFrameOrigin.x+theCurrentPoint.x-theOrigin.x, theFrameOrigin.y+theCurrentPoint.y-theOrigin.y );

		[self setFrameOrigin:[self snapOrigin:theTargetFrameOrigin]];

//		We don't want to be too much desynchronized with the window server, or window movement will be sluggish (only slightly because the mouse location is taken from outside the stream, but noticable anyway)
		[[NSDPSContext currentContext] wait];

//NSLog( @"Y = %f", theFrameOrigin.y+theCurrentPoint.y-theOrigin.y );

//		[self discardEventsMatchingMask: NSLeftMouseDraggedMask beforeEvent:nil];

		theEvent = [self nextEventMatchingMask:NSLeftMouseUpMask|NSLeftMouseDraggedMask];
	}	while ([theEvent type]!=NSLeftMouseUp);
}

@end

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

@implementation DockWindow(NSWindow_Overrides)

- (BOOL)canBecomeKeyWindow
{	return YES;
}

@end
