// -------------------------------------------------------------------------------------
//	EditFormatter.h
//  This software is without warranty of any kind.  Use at your own risk.
// -------------------------------------------------------------------------------------

#import <objc/objc.h>
#import <appkit/appkit.h>
#import <mach/mach.h>
#import <dbkit/dbkit.h>
#import "DataTable.h"
#import "EditFormatter.h"

// -------------------------------------------------------------------------------------
// NXRect abbreviations
#define	X				origin.x
#define	Y				origin.y
#define	W				size.width
#define	H				size.height

// -------------------------------------------------------------------------------------
// MyTextFieldCell
@interface _MyTextFieldCell : TextFieldCell
{
	float		cellTextGray;
}
@end
@implementation _MyTextFieldCell
- setEditable:(BOOL)flag
{
	return [super setEditable:flag];
}
- setTextAttributes:textObj
{
	[super setTextAttributes:textObj];
	[textObj setTextGray:cellTextGray];
//	[textObj setBackgroundGray:cFlags1.bezeled ? NX_WHITE : NX_LTGRAY];
//	[textObj setTextColor:NXConvertGrayToColor([self isEnabled] ? NX_BLACK : NX_DKGRAY)];
//	[textObj setBackgroundColor:NXConvertGrayToColor(cFlags1.bezeled ? NX_WHITE : NX_LTGRAY)];
    return textObj;
}
- setTextGray:(float)aGray
{
	cellTextGray = aGray;
	return self;
}
@end
// -------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------
@implementation EditFormatter
// -------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------
// initialization

/* init */
- init
{
	[super init];
	[drawCell free]; // free old drawCell
	drawCell = [[_MyTextFieldCell allocFromZone:[self zone]] initTextCell:NULL];
	[drawCell setTextGray:NX_BLACK];
	[drawCell setBezeled:NO];
	[drawCell setBordered:NO];
	[drawCell setBackgroundTransparent:YES];
	[drawCell setEditable:NO];
	return self;
}

// -------------------------------------------------------------------------------------
// get value

- getValueAt:(unsigned int)row :(unsigned int)col
	withAttributes:(id <DBTableVectors>)ra :(id <DBTableVectors>)ca
	usePositions:(BOOL)ur :(BOOL)uc;
{
	u_int	r = ur? row : (u_int)[ra identifier];
	u_int	c = uc? col : (u_int)[ca identifier];
	[super getValueAt:row:col withAttributes:ra:ca usePositions:ur:uc];
	[drawCell setTextGray:([dataSource verifyValueAt:r:c]?NX_BLACK:NX_DKGRAY)];
	return value;
}

// -------------------------------------------------------------------------------------
@end
