Re: Expanding split view with double click
Re: Expanding split view with double click
- Subject: Re: Expanding split view with double click
- From: Sailesh Agrawal <email@hidden>
- Date: Mon, 3 Feb 2003 06:44:07 -0500
Hm.. I tried playing with the code some more. It looks like the
canCollapseSplitView function is being called twice when when the user
double clicks. The following modification make the code work somewhat.
If any one has a more elegant solution I'd be happy to see it.
- (void) collapseView {
NSView *leftView=[[splitView subviews] objectAtIndex:0];
NSView *rightView=[[splitView subviews] objectAtIndex:1];
lastLeftFrame = [leftView frame];
lastRightFrame = [rightView frame];
lastRightFrame.size.width -= lastLeftFrame.size.width;
[rightView setFrame: lastRightFrame];
lastLeftFrame.size.width = 0;
[leftView setFrame: lastLeftFrame];
[splitView adjustSubviews];
collapsed = TRUE;
}
- (void) uncollapseView {
NSView *leftView=[[splitView subviews] objectAtIndex:0];
NSView *rightView=[[splitView subviews] objectAtIndex:1];
[leftView setFrame:lastLeftFrame];
[rightView setFrame:lastRightFrame];
[splitView adjustSubviews];
collapsed = FALSE;
}
static int x = 1;
- (BOOL)splitView:(NSSplitView *)sender
canCollapseSubview:(NSView*)subview
{
if(subview == [[leftTextField superview] superview]) {
NSEvent *event = [[leftTextField window] currentEvent];
if ([event type] == NSLeftMouseDown && [event clickCount] == 2)
{
x++;
if (x % 2) return NO;
if (collapsed) {
[self uncollapseView];
} else {
[self collapseView];
}
}
}
return NO;
}
On Sunday, Feb 2, 2003, at 22:45 Canada/Eastern, Sailesh Agrawal wrote:
In Mail.app you can double click the split view to collapse and expand
it, I'm trying to write code to do the same. The code below works for
collapsing the split view, but it does nothing for expanding. Any
help would be greatly appreciated:
- (void) collapseView {
NSView *leftView=[[splitView subviews] objectAtIndex:0];
NSView *rightView=[[splitView subviews] objectAtIndex:1];
if (![splitView isSubviewCollapsed:leftView]) {
NSRect leftFrame=[leftView frame];
NSRect rightFrame = [rightView frame];
lastLeftWidth = leftFrame.size.width;
lastRightWidth = rightFrame.size.width;
rightFrame.size.width += leftFrame.size.width;
[rightView setFrame:rightFrame];
leftFrame.size.width = 0;
[leftView setFrame:leftFrame];
[splitView adjustSubviews];
}
}
- (void) uncollapseView {
NSView *leftView=[[splitView subviews] objectAtIndex:0];
NSView *rightView=[[splitView subviews] objectAtIndex:1];
if ([splitView isSubviewCollapsed:leftView]) {
NSRect leftFrame=[leftView frame];
NSRect rightFrame = [rightView frame];
leftFrame.size.width = lastLeftWidth;
[leftView setFrame:leftFrame];
rightFrame.size.width = lastRightWidth;
[rightView setFrame:rightFrame];
[splitView adjustSubviews];
collapsed = FALSE;
}
}
- (BOOL)splitView:(NSSplitView *)sender
canCollapseSubview:(NSView*)subview
{
if(subview == [[leftTextField superview] superview]) {
NSEvent *event = [[leftTextField window] currentEvent];
if ([event type] == NSLeftMouseDown && [event clickCount] ==
2) {
if (collapsed) {
[self uncollapseView];
} else {
[self collapseView];
}
}
}
return YES;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.