/***** RMenuVars.m -- MenuCellCover variable holder object implementation
	NeXTstep Measurement Kit
	by Alex Meyer <ameyer@phoenix.Princeton.EDU>
	for computer science senior thesis
	24 April 1992 -- created from RButtonVars.m
*****/

#import <stdlib.h>
#import <stdio.h>
#import <string.h>
#import <appkit/Application.h>
#import "RMenuVars.h"

@implementation RMenuVars

- init	/* should not be used */
{
	[self free];
	return (nil);
}


- initString:(const char *)str
	tag:(int)tg
	rect:(const NXRect *)rect
{
	char temp[512];

	[super init];
	linker = NXGetNamedObject(LINKERNAME,NXApp);
	sprintf(temp,"%s|%d|%f|%f|%f|%f",str,tg,
		rect->origin.x,rect->origin.y,
		rect->size.width,rect->size.height);
	key = NXUniqueString(temp);
	lastHitTime = 0;
	stats.numHits = 0;
	stats.numCancel = 0;
	stats.timeIn = 0;
	stats.timeBetween = 0;
	[linker connect:self];
	return (self);
}


- incHits
{
	++stats.numHits;
	return (self);
}


- incCancel
{
	++stats.numCancel;
	return (self);
}


- timeFrom:(double)time0
	to:(double)time1
{
	stats.timeIn += time1 - time0;
	if (lastHitTime)
		stats.timeBetween += time0 - lastHitTime;
	lastHitTime = time1;
	return (self);
}


- (unsigned)type
{
	return (TM_MENU);
}


- (NXAtom)key
{
	return (key);
}


- (NXAtom)desc
{
	return (NXUniqueString("{iidd}"));
}


- (unsigned)statsSize
{
	return (sizeof(stats));
}


- (void *)copyOfStats
{
	void *cpy;

	cpy = malloc(sizeof(stats));
	memcpy(cpy,&stats,sizeof(stats));
	return (cpy);
}


- copyInStats:(void *)NewStats
{
	memcpy(&stats,NewStats,sizeof(stats));
	return (self);
}

@end
