/*
 *	MouseView --  John Glover, adapted from MouseTracker by Randy Nelson
 *	An abstract class that manages a modal loop for tracking the mouse
 *
 */

#import "MouseView.h"
#import <appkit/Window.h>
#import <appkit/Application.h>
#import <appkit/Control.h>
#import <dpsclient/psops.h>
#import <dpsclient/wraps.h>

@implementation MouseView



- setTrackingRect:sender
{
    NXRect myFrame = frame;
    [[self superview] convertRect:&myFrame toView:nil];
    [window setTrackingRect:&myFrame
	    inside:NO
	    owner:self
	    tag:23
	    left:NO
	    right:NO];
    return self;
}

- mouseDown:(NXEvent *)e
 {
    NXPoint startPoint = e->location, nextPoint;
    int looping = YES;
    int oldMask = [window addToEventMask:NX_MOUSEDRAGGEDMASK];
    
    /* do first mouse down action */
    [self convertPoint:&startPoint fromView:nil];
    [self mouseDownAction:&startPoint];
    
    while (looping){
	e = [NXApp getNextEvent:NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK];
	nextPoint = e->location;
	[self convertPoint:&nextPoint fromView:nil];
	if(e->type == NX_MOUSEDRAGGED){
//	    [superview autoscroll:e];

	    /* do continuing mouse dragged action */
	    [self mouseDraggedAction:&nextPoint];
	}
	else{
	    looping = NO;

	    /* do mouse up action */
	    [self mouseUpAction:&nextPoint];
	}	
    }
    [window setEventMask:oldMask];
    return self;
 }
 
- mouseEntered:(NXEvent *)e
{
    return [super mouseEntered:e];
}

- mouseExited:(NXEvent *)e
{
    return [super mouseExited:e];
}

- mouseDownAction:(NXPoint *)currentLocation
{	
    return self;
}

- mouseDraggedAction:(NXPoint *)currentLocation
{
    return self;
}

- mouseUpAction:(NXPoint *)currentLocation
{
    return self;
}

@end
