Re: NSSplitView can't expand once collapsed
Re: NSSplitView can't expand once collapsed
- Subject: Re: NSSplitView can't expand once collapsed
- From: "Qi Liu" <email@hidden>
- Date: Thu, 13 Nov 2008 05:10:19 +0000
Hi all,
From apple leopard's release notes, I find this:
http://developer.apple.com/releasenotes/Cocoa/AppKit.html#NSSplitView
NSSplitView now uses -[NSView setHidden:] when collapsing and uncollapsing
a subview instead of setting the origin of the subview's frame somewhere
far, far way. One result is that controls inside collapsed subviews can no
longer hold onto the key focus, and can therefore no longer interfere with a
window's tabbing behavior.
Accessibility: because of NSSplitView's use of -[NSView setHidden:],
collapsed subviews are automatically no longer present in the accessibility
hierarchy.
-[NSSplitView adjustSubviews] now reliably apportions space to uncollapsed
subviews even when their total width (in vertical split views) or height
(horizontal) is zero when it is invoked.
So I'm sorry, my previous code is not available in Tiger. I find when a
subview of splitview is collapsed, its origin is (1000000, 1000000), though
in Xcode2.4's document, it says "A collapsed subview is hidden but retained
by the NSSplitView object, with the same size it had before it was
collapsed."
Right now, in Tiger even I have changed a subview's origin to far, far
away, I couldn't make the view collapsed. Can anyone give me some advice?
Thanks in advance!
2008/11/11 Qi Liu <email@hidden>
> Hi,
> At first, I think just as you mentioned, and I want to file a bug too.
> But the view being collapsed is not actually being collapsed, it is just
> being set *HIDDEN*, and its size remains unchanged. Suppose the splitview is
> horizontal and we have 2 views, leftView and rightView. We overrided the
> following code:
>
> - (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView
> *)subview
> {
> return YES;
> }
> - (float)splitView:(NSSplitView *)sender
> constrainMinCoordinate:(float)proposedMin ofSubviewAt:(NSInteger)offset
> {
> return proposedMin + 100.0;
> }
> - (float)splitView:(NSSplitView *)sender
> constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(NSInteger)offset
> {
> return proposedMax - 100.0;
> }
>
> If we want to collapse/expand leftView, we better invoke following
> function:
> - (IBAction)collapse:(id)sender
> {
> NSView * leftview = [[splitview subviews] objectAtIndex:0];
> NSView * rightview = [[splitview subviews] objectAtIndex:1];
> NSRect leftFrame = [leftview frame];
> NSRect rightFrame = [rightview frame];
> rightFrame.origin.x = [splitview dividerThickness];
> rightFrame.size.width += leftFrame.size.width;
> [leftview setHidden:YES];
> [rightview setFrame:rightFrame];
> }
> - (IBAction)expand:(id)sender
> {
> NSView * leftview = [[splitview subviews] objectAtIndex:0];
> NSView * rightview = [[splitview subviews] objectAtIndex:1];
> NSRect leftFrame = [leftview frame];
> NSRect rightFrame = [rightview frame];
> rightFrame.size.width -= leftFrame.size.width;
> rightFrame.origin.x = leftFrame.size.width + [splitview dividerThickness];
> [leftview setHidden:NO];
> [rightview setFrame:rightFrame];
> }
>
> Personally I don't think setting width of leftview to zero is a good
> idea. Hope this can be helpful.
>
> =============================================
> Qi Liu
> --Stay Hungry. Stay Foolish.
> --You've got to find what you love.
> =============================================
>
>
>> On Sat, Mar 01, 2003 at 09:04:37PM -0800, matt neuburg wrote:
>>
>> >* I think I'm seeing a bug, as follows.*
>> >* *
>> >* I have an NSSplitView with two subviews. If I "collapse" one of the*
>> >* subviews programatically (i.e. I set its height to zero, so that the
>> user*
>> >* sees only the other subview), then I can expand it again later*
>> >* programatically (e.g. I set both subviews to have the same height, and
>> *
>> >* adjust subviews).*
>> >* *
>> >* But if (via the delegate methods) I permit the user to collapse a
>> subview*
>> >* by hand, I can't find a way to expand it again programatically.
>> Everything*
>> >* I try gives funky results, wrong sizes, drawing glitches, and so on.
>> If*
>> >* anyone has counterexample code showing that there is a way to expand a
>> *
>> >* subview that the user has collapsed, I'd like to see it. Thanks - m.*
>>
>> Yup, this is a total mess. Horizontal splits are even worse as you
>> can't even uncollapse from code after a programmatic collapse. This
>> is my workaround, though it would need to be adapted for your
>> purposes.
>>
>> <http://cocoa.mamasam.com/COCOADEV/2003/02/2/57202.php>
>>
>> Please file a bug on this issue (I did, #3179051, which is not marked
>> as a duplicate).
>>
>> --
>> =Nicholas Riley <email@hidden> | <http://www.uiuc.edu/ph/www/njriley>
>> Pablo Research Group, Department of Computer Science and
>> Medical Scholars Program, University of Illinois at Urbana-Champaign
>>
>
>
_______________________________________________
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