* Added MYReturnError.
* Better iPhone support in ExceptionUtils.
* Make sure "All Tests Passed/Failed" message is always logged.
2 // MYAnimatingSplitView.m
5 // Created by Jens Alfke on 7/10/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
9 #import "MYAnimatingSplitView.h"
13 #define kDefaultAnimationTime 0.3
16 @interface MYAnimatingSplitView ()
17 @property (readwrite) BOOL isLiveResizing;
21 @implementation MYAnimatingSplitView
24 @synthesize animationTime=_animationTime;
27 - (void) my_animateDividerToPosition: (float)pos
29 const NSTimeInterval maxTime = _animationTime ?: kDefaultAnimationTime;
31 NSTimeInterval startTime = TimeIntervalSinceBoot();
32 float startPos = self.dividerPosition;
33 const NSTimeInterval animationTime = maxTime * fabs(pos-startPos)/self.frame.size.height;
36 fract = (float) MIN(1.0, (TimeIntervalSinceBoot()-startTime)/animationTime);
37 float curPos = startPos + fract*(pos-startPos);
38 [self setPosition: curPos ofDividerAtIndex: 0];
39 [self.window displayIfNeeded];
41 }while( fract < 1.0 );
45 - (void) getDividerPositionMin: (float*)outMin max: (float*)outMax
47 *outMin = [self.delegate splitView: self
48 constrainMinCoordinate: [self minPossiblePositionOfDividerAtIndex: 0]
50 *outMax = [self.delegate splitView: self
51 constrainMaxCoordinate: [self maxPossiblePositionOfDividerAtIndex: 0]
55 - (float) dividerPosition
57 return NSMaxY([[self.subviews objectAtIndex: 0] frame]);
60 - (void) setDividerPosition: (float)pos
63 [self getDividerPositionMin: &minPos max: &maxPos];
64 NSView *targetView = [[self subviews] objectAtIndex:0];
65 NSRect startFrame = [targetView frame];
67 // First uncollapse any collapsed subview:
68 if( [self isSubviewCollapsed: targetView] )
69 [self setPosition: minPos ofDividerAtIndex: 0];
70 else if( startFrame.size.height > maxPos )
71 [self setPosition: maxPos ofDividerAtIndex: 0];
73 [self my_animateDividerToPosition: pos];
76 - (float) dividerFractionalPosition
78 float minPos, maxPos, pos=self.dividerPosition;
79 [self getDividerPositionMin: &minPos max: &maxPos];
80 float denom = maxPos-minPos;
84 return (pos-minPos)/denom;
87 - (void) setDividerFractionalPosition: (float)fract
90 [self getDividerPositionMin: &minPos max: &maxPos];
91 self.dividerPosition = roundf( minPos + fract*(maxPos-minPos) );
95 - (void) collapseSubviewAtIndex: (int)index animate: (BOOL)animate
97 if( ! [self isSubviewCollapsed: [self.subviews objectAtIndex: index]] ) {
98 float pos = index==0 ?[self minPossiblePositionOfDividerAtIndex: 0]
99 :[self maxPossiblePositionOfDividerAtIndex: 0];
101 [self my_animateDividerToPosition: pos];
103 [self setPosition: pos ofDividerAtIndex: 0];
107 - (void) collapseSubviewAtIndex: (int)index
109 [self collapseSubviewAtIndex: index animate: YES];
114 - (BOOL) isLiveResizing
116 return _isLiveResizing;
119 - (void) setIsLiveResizing: (BOOL)inLiveResize
121 _isLiveResizing = inLiveResize;
122 id delegate = self.delegate;
123 if( [delegate respondsToSelector: @selector(splitView:inLiveResize:)] )
124 [delegate splitView: self inLiveResize: inLiveResize];
128 - (void)viewWillStartLiveResize
130 [super viewWillStartLiveResize];
131 self.isLiveResizing = YES;
134 - (void) viewDidEndLiveResize
136 [super viewDidEndLiveResize];
137 self.isLiveResizing = NO;