Re: Overcoming crappiness of NSSplitView - what's the magic?
Re: Overcoming crappiness of NSSplitView - what's the magic?
- Subject: Re: Overcoming crappiness of NSSplitView - what's the magic?
- From: Sandy McGuffog <email@hidden>
- Date: Tue, 15 Sep 2009 16:58:43 +0200
Below is what I ended up doing to solve a similar problem. Which is
really seriously ugly, but has worked for me. Your mileage may
vary......
Sandy
- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:
(NSSize)oldSize
{
NSArray *subviewList = [sender subviews];
NSView *leftView = [subviewList objectAtIndex:0];
if ([leftView frame].origin.x != 0) {
leftView = [subviewList objectAtIndex:1];
}
NSRect leftFrame;
leftFrame.size.width = (oldSize.width - [sender dividerThickness])
*splitFactor;
leftFrame.size.height = oldSize.height;
leftFrame.origin = NSMakePoint(0,0);
[leftView setFrame:leftFrame];
[sender adjustSubviews];
}
- (float)splitView:(NSSplitView *)sender constrainSplitPosition:(float)
proposedPosition ofSubviewAt:(int)offset
{
splitFactor = (proposedPosition+[sender dividerThickness]/2)/((float)
[sender frame].size.width);
return proposedPosition;
}
- (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)
proposedMin ofSubviewAt:(int)offset
{
if (offset == 0) {
return 30;
}
else {
return proposedMin;
}
}
- (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)
proposedMax ofSubviewAt:(int)offset
{
if (offset == 0) {
return ((float) [sender frame].size.width - (30 + [sender
dividerThickness]));
}
else {
return proposedMax;
}
}
On 15 Sep 2009, at 4:01 PM, Graham Cox wrote:
Ok, I'm beating my head on this one, wasting time I have better
things to spend it on. NSSplitView is a travesty, but we're stuck
with it, so I need to know the magic incantation of delegate methods
and other voodoo needed to implement the following for a split view
with one upper and one lower pane.
1. When I drag the splitter directly, it moves allowing me to
position it where I want within the constrained min and max of the
contained views.
2. When the window resizes I want the split to stay exactly where it
is relative to the top of the window. I do not want it to move
proportionally which seems to be the default. In other words the
window resize affects the bottom pane only, even though the top one
can be resized by the split. Whoever decided that was a sensible
behaviour for the default anyway?
3. When the window is resized programatically as well as drag-
resized, 2. needs to be true also.
This seems so simple and obvious that I'm finding it very
frustrating that nothing I have tried works.
What I have tried:
- (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:
(NSView *)subview
I've tried returning NO for the times when the window is being
resized, assuming that this would effectively lock the split in
place. It's not even called except once when the view is
instantiated. I'm guessing then that this is meant to indicate the
general disposition of view splitting, called just once for all
time. The docs are unclear on this to say the least.
- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:
(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex
This is at only called during manual dragging, so can't be used to
constrain the split during window resize, as even though the split
is being moved at that time, this isn't checked. In any case there's
no way to obtain the current split position at the start of the
window resize so I can return it to effect a "lock".
- (void)splitViewWillResizeSubviews:(NSNotification *)aNotification
This is called in both cases - dragging the split and resizing the
window. But what can I do with it? Since there's no way to get the
split position at the start of a resize I can't set it from here or
anywhere else.
Any ideas what I can do?
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden