/***** ScrollerCover.m -- ScrollerCover object implementation
	NeXTstep Measurement Kit
	by Alex Meyer <ameyer@phoenix.Princeton.EDU>
	for computer science senior thesis
	24 April 1992 -- created from old RScroller.m
*****/

#import <sys/time.h>
#import <appkit/Application.h>
#import "RScrollerVars.h"
#import "ScrollerCover.h"

#define VARSNAME ("ScrollerVars")

#define MICRO (1000000.0)
#define DOUBLETIME(stv) ((double) (((unsigned long) (stv).tv_sec) \
	+ (((unsigned long) (stv).tv_usec) / MICRO)))

@implementation ScrollerCover

- makeVars
{
	id vars;
	const char *nm;

	if (sFlags.isHoriz)	/* cheesey cop-out for names */
		nm = "horiz";
	else
		nm = "vert";
	vars = [RScrollerVars alloc];
	[vars initString:nm
		tag:tag
		rect:&frame];
	NXNameObject(VARSNAME,vars,self);
	return (vars);
}


- mouseDown:(NXEvent *)theEvent
{
	id vars;
	int index;
	double time0,time1;
	struct timeval start,finish;
	struct timezone zone;

	gettimeofday(&start,&zone);
	[super mouseDown:theEvent];
	gettimeofday(&finish,&zone);
	time0 = DOUBLETIME(start);
	time1 = DOUBLETIME(finish);
	vars = NXGetNamedObject(VARSNAME,self);
	if (!(vars))
		vars = [self makeVars];
	[vars incHits];
	switch (hitPart) {
		case (NX_KNOB):
			[vars incKNOB];
			break;
		case (NX_DECPAGE):
			[vars incDECPAGE];
			break;
		case (NX_INCPAGE):
			[vars incINCPAGE];
			break;
		case (NX_DECLINE):
			[vars incDECLINE];
			break;
		case (NX_INCLINE):
			[vars incINCLINE];
			break;
		case (NX_KNOBSLOT):
			[vars incKNOBSLOT];
			break;
		default:
			break;
	}
	[vars timeFrom:time0
		to:time1];
	index = curValue * SCROLLERHIST;
	if (index >= SCROLLERHIST)
		index = SCROLLERHIST - 1;
	[vars incHist:index];
	return (self);
}

@end

#undef DOUBLETIME
#undef MICRO
#undef VARSNAME
