#import "StretchingDelegate.h"

@implementation StretchingDelegate

- (void) rebuildTable:(NSNotification *)inNotification
{
	NSArray *columns = [oTable tableColumns];
	int numberOfColumns = [columns count];
	float spacingWidth = [oTable intercellSpacing].width;
	float tableWidth = [oTable bounds].size.width;
	float firstColWidth = 200.0;		// constant width for first column

	// Calculate the width of the rest of the table columns by dividing up the remaining space
	float remainingWidth = tableWidth - firstColWidth - spacingWidth;
	float colWidth  = (remainingWidth / (numberOfColumns-1)) - spacingWidth;
	int i;

	// First, set the first column to a constant value
	[[columns objectAtIndex:0] setWidth:firstColWidth];

	// Now, set the rest of the columns starting at index 1
	for ( i = 1 ; i < numberOfColumns ; i++ )
	{
		NSTableColumn *column = [columns objectAtIndex:i];
		[column setWidth:colWidth];
	}
}

- (void)awakeFromNib
{
	[[NSNotificationCenter defaultCenter]
		addObserver:self
		   selector:@selector(rebuildTable:)
			   name:NSViewFrameDidChangeNotification
			 object:[oTable enclosingScrollView]];	// rebuild table when the overall table gets changed
	[self rebuildTable:nil];		// force an initial rebuild
}


@end
