maxPossiblePositionOfDividerAtIndex: for pre-Mac OS X 10.5

The NSSplitView for the MacOS X 10.5 has a few convenience messages.
However, what I’m sorry about it is that they can’t be used for pre-Mac OS X 10.5.
For example, maxPossiblePositionOfDividerAtIndex: is quite useful because minimum width of the right most subview or maximum widh of the left most subview can be enforced for a view with two sub panes divided horizontally.

- (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset
	NSRect boundsRect = [self bounds];
	NSArray *subviews = [self subviews];

	NSRect leftBoundsRect = [[subviews objectAtIndex:0] bounds];
	NSRect rightBoundsRect = [[subviews objectAtIndex:1] bounds];

	float rightLimit;
	rightLimit = boundsRect.size.width - kViewerPaneWidth - [self dividerThickness];

	if( proposedMax > rightLimit )
		return rightLimit;
		return proposedMax;

The passed parameter, proposedMax, represents the current position of the divider. – splitView:constrainMaxCoordinate:ofSubviewAt: keeps being called when the divider is moved.
kViewerPaneWidth is the minimum width of a right-side pane you want to ensure its minimum width.
And the value returned by this message enforces the right-most position of the divider. If you want to implement it for a splitview divided vertically, boundsRect.size.width should be replaced with height.

With the code above, you can ensure the minimum width for the right-most pane. Take a look at this.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: