/***** ButtonCellCover.m -- ButtonCellCover object implementation
	NeXTstep Measurement Kit
	by Alex Meyer <ameyer@phoenix.Princeton.EDU>
	for computer science senior thesis
	23 April 1992 -- created from RButtonCell.m
	24 April 1992 -- used named object to trigger initialization
*****/

#import <sys/time.h>
#import <appkit/Application.h>
#import "RButtonVars.h"
#import "ButtonCellCover.h"

#define VARSNAME ("ButtonVars")

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

@implementation ButtonCellCover

- makeVarsRect:(const NXRect *)rect
{
	id vars;

	vars = [RButtonVars alloc];
	[vars initString:contents
		tag:tag
		rect:rect];
	NXNameObject(VARSNAME,vars,self);
	return (vars);
}



- (BOOL)trackMouse:(NXEvent *)theEvent
	inRect:(const NXRect *)cellFrame
	ofView:controlView
{
	id vars;
	BOOL res;
	double time0,time1;
	struct timeval start,finish;
	struct timezone zone;

	gettimeofday(&start,&zone);
	res = [super trackMouse:theEvent
		inRect:cellFrame
		ofView:controlView];
	gettimeofday(&finish,&zone);
	time0 = DOUBLETIME(start);
	time1 = DOUBLETIME(finish);
	vars = NXGetNamedObject(VARSNAME,self);
	if (!(vars))
		vars = [self makeVarsRect:cellFrame];
	[vars incHits];
	if (!(res))
		[vars incCancel];
	[vars timeFrom:time0
		to:time1];
	return (res);
}

@end

#undef DOUBLETIME
#undef MICRO
#undef VARSNAME
