
// TablePrinterInspector
//
// By Eric T. Seymour, NeXT Computer, Inc.
//
// You may freely copy, distribute, and reuse the code in this example.
// NeXT disclaims any warranty of any kind, expressed or  implied, as to its
// fitness for any particular use.
//
// This file looks best when using tabstops of 3.


#import "TablePrinterInspector.h"
#import "TablePrinter.h"
#import "DBTableViewPrinter.h"

@implementation TablePrinterInspector

- init
{
	char	path[MAXPATHLEN + 1];
	id		bundle;
    
	[super init];
    
	// Load my nib
	bundle = [NXBundle bundleForClass:[TablePrinter class]];
	[bundle getPath:path forResource:"TablePrinterInspector" ofType:"nib"];
	[NXApp loadNibFile:path owner:self withNames:NO fromZone:[self zone]];
	return self;
}

- ok:sender
{
	// ask for the printerView of object, because we are going to set
	// preferences directly.
	id	pv = [object printerView];

	// Set Toggles
	[pv setColumnHeadersBezeled:[headerBezelToggle state]];
	[pv setForceDrawColor:[forceColorToggle state]];
	[pv setPageNumbersEnabled:[pageNumbersToggle state]];
	[pv setRowNumbersEnabled:[rowNumbersToggle state]];
	[pv setGridLinesOn:[gridLinesToggle state]];
	[pv setSelectedRowsOnly:[selectedRowsToggle state]];

	// Set Fields
	[pv setStartingPageNumber:[startingPageNumber intValue]];
	[pv setStartingRowNumber:[startingRowNumber intValue]];
	[pv setPageNumberSeparator:[pageNumberSeparator stringValue][0]];
	[pv setRowNumbersTitle:[rowNumberHeader stringValue]];

	// Set Colors
	[pv setRowNumbersTextColor:[rowNumberTextColor color]];
	[pv setRowNumbersBackColor:[rowNumberBackColor color]];
	[pv setColumnHeadersTextColor:[columnHeaderTextColor color]];
	[pv setColumnHeadersBackColor:[columnHeaderBackColor color]];
	[pv setGridLinesColor:[gridLineColor color]];
	[pv setPageNumberColor:[pageNumberColor color]];
	[pv setBackgroundColor:[backgroundColor color]];

	return [super ok:sender];
}

- revert:sender
{
	// ask for the printerView of object, because we are going to get
	// preferences directly.
	id		pv = [object printerView];
	char	buf[2] = {0,0};
	
	// Reset Toggles
	[headerBezelToggle setState:[pv isColumnHeadersBezeled]];
	[forceColorToggle setState:[pv isForceDrawColor]];
	[pageNumbersToggle setState:[pv isPageNumbersEnabled]];
	[rowNumbersToggle setState:[pv isRowNumbersEnabled]];
	[gridLinesToggle setState:[pv isGridLinesOn]];
	[selectedRowsToggle setState:[pv isSelectedRowsOnly]];

	// Reset Fields
	[startingPageNumber setIntValue:[pv startingPageNumber]];
	[startingRowNumber setIntValue:[pv startingRowNumber]];
	buf[0] = [pv pageNumberSeparator];
	[pageNumberSeparator setStringValue:buf];
	[rowNumberHeader setStringValue:[pv rowNumbersTitle]];

	// Reset Colors
	[rowNumberTextColor setColor:[pv rowNumbersTextColor]];
	[rowNumberBackColor setColor:[pv rowNumbersBackColor]];
	[columnHeaderTextColor setColor:[pv columnHeadersTextColor]];
	[columnHeaderBackColor setColor:[pv columnHeadersBackColor]];
	[gridLineColor setColor:[pv gridLinesColor]];
	[pageNumberColor setColor:[pv pageNumberColor]];
	[backgroundColor setColor:[pv backgroundColor]];
	
	// Force a display
	[[box window] display];

	return [super revert:sender];
}

- (BOOL)wantsButtons
{
	return NO;
}

- textDidEnd:textObject endChar:(unsigned short)whyEnd
{
	[self ok:self];
	return self;
}

@end
