//
//  MPT_SplitViewConstrainer.m
//  AUCoderDemo
//
//  Created by Andrew Salamon on 11/8/06.
//  Copyright 2006 Machine Perception Laboratory, University of California San Diego. All rights reserved.
//

#import "MPT_SplitViewConstrainer.h"


@implementation MPT_SplitViewConstrainer
- (float)minLeftPane
{
    return minLeftPane;
}

- (void)setMinLeftPane:(float)value
{
    minLeftPane = value;
}

- (float)minRightPane
{
    return minRightPane;
}

- (void)setMinRightPane:(float)value
{
    minRightPane = value;
}

// Begin SplitView delegate methods
- (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset
{
	return minLeftPane;
}

- (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedCoord ofSubviewAt:(int)offset
{
	float width = [sender bounds].size.width;
	return width - [sender dividerThickness] - minRightPane;
}

- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize
{
	//        float width = [sender bounds].size.width;
	float min = [self splitView:sender constrainMinCoordinate:0.0 ofSubviewAt:0];
	//        float max = [self splitView:sender constrainMaxCoordinate:0.0 ofSubviewAt:0];
	
	if( [splitViewLeft frame].size.width < min )
	{
		// adjust ourselves
		NSSize size = [splitViewLeft frame].size;
		size.width = min;
		[splitViewLeft setFrameSize:size];
		[sender adjustSubviews];
	}
	else
		[sender adjustSubviews];
}

- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview
{
    return NO;
}

- (float)splitView:(NSSplitView *)sender constrainSplitPosition:(float)proposedPosition ofSubviewAt:(int)offset
{
    return proposedPosition;
}
@end
