# HG changeset patch # User Jens Alfke # Date 1215971142 25200 # Node ID ce9c83f7ec14d049822430b2188936cecf1ad0ad # Parent 06e7d03fd23e9e896550ce516a7bcb1f5100789b * Minor fixes to glitches detected by the clang static analyzer. * Added MYAnimatingSplitView class. diff -r 06e7d03fd23e -r ce9c83f7ec14 CollectionUtils.h --- a/CollectionUtils.h Tue Jun 24 12:05:24 2008 -0700 +++ b/CollectionUtils.h Sun Jul 13 10:45:42 2008 -0700 @@ -7,6 +7,7 @@ // #import +#define _MYUTILITIES_COLLECTIONUTILS_ 1 // Collection creation conveniences: diff -r 06e7d03fd23e -r ce9c83f7ec14 ExceptionUtils.m --- a/ExceptionUtils.m Tue Jun 24 12:05:24 2008 -0700 +++ b/ExceptionUtils.m Sun Jul 13 10:45:42 2008 -0700 @@ -166,7 +166,6 @@ // From: int mib[4]; size_t bufSize = 0; - int local_error = 0; struct kinfo_proc kp; mib[0] = CTL_KERN; @@ -175,8 +174,8 @@ mib[3] = getpid(); bufSize = sizeof (kp); - if ((local_error = sysctl(mib, 4, &kp, &bufSize, NULL, 0)) < 0) { - Warn(@"Failure calling sysctl"); + if (sysctl(mib, 4, &kp, &bufSize, NULL, 0) < 0) { + Warn(@"Error %i calling sysctl",errno); return NO; } return (kp.kp_proc.p_flag & P_TRACED) != 0; diff -r 06e7d03fd23e -r ce9c83f7ec14 FileAlias.m --- a/FileAlias.m Tue Jun 24 12:05:24 2008 -0700 +++ b/FileAlias.m Sun Jul 13 10:45:42 2008 -0700 @@ -199,7 +199,7 @@ FSRef matches[count]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 - if( ! FSMatchAliasBulk(fromRefPtr, rules, _alias, &count, matches, &wasChanged, NULL, NULL), error ) { + if( ! CheckOSErr( FSMatchAliasBulk(fromRefPtr, rules, _alias, &count, matches, &wasChanged, NULL, NULL), error) ) { NSLog(@"%@: FSMatchAliasBulk failed!",self); return nil; } diff -r 06e7d03fd23e -r ce9c83f7ec14 MYAnimatingSplitView.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MYAnimatingSplitView.h Sun Jul 13 10:45:42 2008 -0700 @@ -0,0 +1,43 @@ +// +// MYAnimatingSplitView.h +// Cloudy +// +// Created by Jens Alfke on 7/10/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import + + +@interface MYAnimatingSplitView : NSSplitView +{ + NSTimeInterval _animationTime; + BOOL _isLiveResizing; +} + + +/** The maximum time it will take to animate the divider. (Actual time depends on distance moved.) */ +@property NSTimeInterval animationTime; + +/** Pixel position of the divider (in the splitview's bounds' coordinate system.) + Setting this property animates the divider to the new position. */ +@property float dividerPosition; + +/** Position of the divider, scaled to the range [0..1]. */ +@property float dividerFractionalPosition; + +- (void) collapseSubviewAtIndex: (int)index; +- (void) collapseSubviewAtIndex: (int)index animate: (BOOL)animate; + +/** Returns YES while the splitview itself is being resized (i.e. while the window + is resizing, or a parent splitview is moving its divider.) */ +@property (readonly) BOOL isLiveResizing; + +@end + + +@interface NSObject (MYAnimatingSplitViewDelegate) +/** If the delegate implements this method, it will be called when the splitview + begins and ends live resizing. */ +- (void)splitView: (NSSplitView*)splitView inLiveResize: (BOOL)inLiveResize; +@end diff -r 06e7d03fd23e -r ce9c83f7ec14 MYAnimatingSplitView.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MYAnimatingSplitView.m Sun Jul 13 10:45:42 2008 -0700 @@ -0,0 +1,140 @@ +// +// MYAnimatingSplitView.m +// Cloudy +// +// Created by Jens Alfke on 7/10/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import "MYAnimatingSplitView.h" +#import "DateUtils.h" + + +#define kDefaultAnimationTime 0.3 + + +@interface MYAnimatingSplitView () +@property (readwrite) BOOL isLiveResizing; +@end + + +@implementation MYAnimatingSplitView + + +@synthesize animationTime=_animationTime; + + +- (void) my_animateDividerToPosition: (float)pos +{ + const NSTimeInterval maxTime = _animationTime ?: kDefaultAnimationTime; + + NSTimeInterval startTime = TimeIntervalSinceBoot(); + float startPos = self.dividerPosition; + const NSTimeInterval animationTime = maxTime * fabs(pos-startPos)/self.frame.size.height; + float fract; + do { + fract = (float) MIN(1.0, (TimeIntervalSinceBoot()-startTime)/animationTime); + float curPos = startPos + fract*(pos-startPos); + [self setPosition: curPos ofDividerAtIndex: 0]; + [self.window displayIfNeeded]; + [self.window update]; + }while( fract < 1.0 ); +} + + +- (void) getDividerPositionMin: (float*)outMin max: (float*)outMax +{ + *outMin = [self.delegate splitView: self + constrainMinCoordinate: [self minPossiblePositionOfDividerAtIndex: 0] + ofSubviewAt: 0]; + *outMax = [self.delegate splitView: self + constrainMaxCoordinate: [self maxPossiblePositionOfDividerAtIndex: 0] + ofSubviewAt: 0]; +} + +- (float) dividerPosition +{ + return NSMaxY([[self.subviews objectAtIndex: 0] frame]); +} + +- (void) setDividerPosition: (float)pos +{ + float minPos,maxPos; + [self getDividerPositionMin: &minPos max: &maxPos]; + NSView *targetView = [[self subviews] objectAtIndex:0]; + NSRect startFrame = [targetView frame]; + + // First uncollapse any collapsed subview: + if( [self isSubviewCollapsed: targetView] ) + [self setPosition: minPos ofDividerAtIndex: 0]; + else if( startFrame.size.height > maxPos ) + [self setPosition: maxPos ofDividerAtIndex: 0]; + // Now animate: + [self my_animateDividerToPosition: pos]; +} + +- (float) dividerFractionalPosition +{ + float minPos, maxPos, pos=self.dividerPosition; + [self getDividerPositionMin: &minPos max: &maxPos]; + float denom = maxPos-minPos; + if( denom<=0 ) + return 0.0; + else + return (pos-minPos)/denom; +} + +- (void) setDividerFractionalPosition: (float)fract +{ + float minPos, maxPos; + [self getDividerPositionMin: &minPos max: &maxPos]; + self.dividerPosition = roundf( minPos + fract*(maxPos-minPos) ); +} + + +- (void) collapseSubviewAtIndex: (int)index animate: (BOOL)animate +{ + if( ! [self isSubviewCollapsed: [self.subviews objectAtIndex: index]] ) { + float pos = index==0 ?[self minPossiblePositionOfDividerAtIndex: 0] + :[self maxPossiblePositionOfDividerAtIndex: 0]; + if( animate ) + [self my_animateDividerToPosition: pos]; + else + [self setPosition: pos ofDividerAtIndex: 0]; + } +} + +- (void) collapseSubviewAtIndex: (int)index +{ + [self collapseSubviewAtIndex: index animate: YES]; +} + + + +- (BOOL) isLiveResizing +{ + return _isLiveResizing; +} + +- (void) setIsLiveResizing: (BOOL)inLiveResize +{ + _isLiveResizing = inLiveResize; + id delegate = self.delegate; + if( [delegate respondsToSelector: @selector(splitView:inLiveResize:)] ) + [delegate splitView: self inLiveResize: inLiveResize]; +} + + +- (void)viewWillStartLiveResize +{ + [super viewWillStartLiveResize]; + self.isLiveResizing = YES; +} + +- (void) viewDidEndLiveResize +{ + [super viewDidEndLiveResize]; + self.isLiveResizing = NO; +} + +@end diff -r 06e7d03fd23e -r ce9c83f7ec14 Test.m --- a/Test.m Tue Jun 24 12:05:24 2008 -0700 +++ b/Test.m Sun Jul 13 10:45:42 2008 -0700 @@ -132,6 +132,7 @@ va_list args; va_start(args,message); message = [[[NSString alloc] initWithFormat: message arguments: args] autorelease]; + message = [@"Assertion failed: " stringByAppendingString: message]; va_end(args); } else message = [NSString stringWithUTF8String: condString];