From 8660c72015757f6824db47f1ce86fc84ee4c2e36 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Wed, 8 Jul 2009 11:15:15 -0700 Subject: [PATCH] Fix for scrollers and nib2cib, as well as resizing. Closes #217. Closes #218. Reviewed by me. --- AppKit/CPScrollView.j | 18 +++++--- AppKit/CPScroller.j | 61 +++++++++++++------------ AppKit/Themes/Aristo/ThemeDescriptors.j | 10 ++-- Tools/nib2cib/NSScroller.j | 2 + 4 files changed, 51 insertions(+), 40 deletions(-) diff --git a/AppKit/CPScrollView.j b/AppKit/CPScrollView.j index b89aa3401..ec93beb28 100644 --- a/AppKit/CPScrollView.j +++ b/AppKit/CPScrollView.j @@ -243,21 +243,27 @@ if (shouldShowHorizontalScroller) verticalScrollerHeight -= horizontalScrollerHeight; - [_verticalScroller setFloatValue:(difference.height <= 0.0) ? 0.0 : scrollPoint.y / difference.height - knobProportion:_CGRectGetHeight(contentFrame) / _CGRectGetHeight(documentFrame)]; + [_verticalScroller setFloatValue:(difference.height <= 0.0) ? 0.0 : scrollPoint.y / difference.height]; + [_verticalScroller setKnobProportion:_CGRectGetHeight(contentFrame) / _CGRectGetHeight(documentFrame)]; [_verticalScroller setFrame:_CGRectMake(_CGRectGetMaxX(contentFrame), verticalScrollerY, verticalScrollerWidth, verticalScrollerHeight)]; } else if (wasShowingVerticalScroller) - [_verticalScroller setFloatValue:0.0 knobProportion:1.0]; + { + [_verticalScroller setFloatValue:0.0]; + [_verticalScroller setKnobProportion:1.0]; + } if (shouldShowHorizontalScroller) { - [_horizontalScroller setFloatValue:(difference.width <= 0.0) ? 0.0 : scrollPoint.x / difference.width - knobProportion:_CGRectGetWidth(contentFrame) / _CGRectGetWidth(documentFrame)]; + [_horizontalScroller setFloatValue:(difference.width <= 0.0) ? 0.0 : scrollPoint.x / difference.width]; + [_horizontalScroller setKnobProportion:_CGRectGetWidth(contentFrame) / _CGRectGetWidth(documentFrame)]; [_horizontalScroller setFrame:_CGRectMake(0.0, _CGRectGetMaxY(contentFrame), _CGRectGetWidth(contentFrame), horizontalScrollerHeight)]; } else if (wasShowingHorizontalScroller) - [_horizontalScroller setFloatValue:0.0 knobProportion:1.0]; + { + [_horizontalScroller setFloatValue:0.0]; + [_horizontalScroller setKnobProportion:1.0]; + } [_contentView setFrame:contentFrame]; [_headerClipView setFrame:headerClipViewFrame]; diff --git a/AppKit/CPScroller.j b/AppKit/CPScroller.j index d922603d7..af566614e 100644 --- a/AppKit/CPScroller.j +++ b/AppKit/CPScroller.j @@ -64,9 +64,9 @@ NAMES_FOR_PARTS[CPScrollerKnob] = @"knob"; BOOL _isVertical @accessors(readonly, getter=isVertical); float _knobProportion; - + CPScrollerPart _hitPart; - + CPScrollerPart _trackingPart; float _trackingFloatValue; CGPoint _trackingStartPoint; @@ -104,11 +104,12 @@ NAMES_FOR_PARTS[CPScrollerKnob] = @"knob"; _controlSize = CPRegularControlSize; _partRects = []; - [self setFloatValue:0.0 knobProportion:1.0]; + [self setFloatValue:0.0]; + [self setKnobProportion:1.0]; _hitPart = CPScrollerNoPart; - [self _recalculateIsVertical]; + [self _calculateIsVertical]; } return self; @@ -155,28 +156,17 @@ NAMES_FOR_PARTS[CPScrollerKnob] = @"knob"; return _controlSize; } -// Setting the Knob Position -/*! - Sets the scroller's knob position (ranges from 0.0 to 1.0). - @param aValue the knob position (ranges from 0.0 to 1.0) -*/ -- (void)setFloatValue:(float)aValue +- (void)setObjectValue:(id)aValue { - [super setFloatValue:MIN(1.0, MAX(0.0, aValue))]; - - [self setNeedsLayout]; + [super setObjectValue:MIN(1.0, MAX(0.0, +aValue))]; } -/*! - Sets the position and proportion of the knob. - @param aValue the knob position (ranges from 0.0 to 1.0) - @param aProportion the knob's proportion (ranges from 0.0 to 1.0) -*/ -- (void)setFloatValue:(float)aValue knobProportion:(float)aProportion +- (void)setKnobProportion:(float)aProportion { _knobProportion = MIN(1.0, MAX(0.0001, aProportion)); - [self setFloatValue:aValue]; + [self setNeedsDisplay:YES]; + [self setNeedsLayout]; } /*! @@ -533,15 +523,15 @@ NAMES_FOR_PARTS[CPScrollerKnob] = @"knob"; } -- (void)_recalculateIsVertical +- (void)_calculateIsVertical { // Recalculate isVertical. var bounds = [self bounds], width = _CGRectGetWidth(bounds), height = _CGRectGetHeight(bounds); - + _isVertical = width < height ? 1 : (width > height ? 0 : -1); - + if (_isVertical === 1) [self setThemeState:CPThemeStateVertical]; else if (_isVertical === 0) @@ -552,8 +542,6 @@ NAMES_FOR_PARTS[CPScrollerKnob] = @"knob"; { [super setFrameSize:aSize]; - [self _recalculateIsVertical]; - [self checkSpaceForParts]; [self setNeedsLayout]; } @@ -590,18 +578,16 @@ var CPScrollerControlSizeKey = "CPScrollerControlSize", _controlSize = CPRegularControlSize; if ([aCoder containsValueForKey:CPScrollerControlSizeKey]) _controlSize = [aCoder decodeIntForKey:CPScrollerControlSizeKey]; - + _knobProportion = 1.0; if ([aCoder containsValueForKey:CPScrollerKnobProportionKey]) _knobProportion = [aCoder decodeFloatForKey:CPScrollerKnobProportionKey]; - + _partRects = []; _hitPart = CPScrollerNoPart; - [self _recalculateIsVertical]; -// [self checkSpaceForParts]; -// [self setNeedsLayout]; + [self _calculateIsVertical]; } return self; @@ -616,3 +602,18 @@ var CPScrollerControlSizeKey = "CPScrollerControlSize", } @end + +@implementation CPScroller (Deprecated) + +/*! + Sets the position and proportion of the knob. + @param aValue the knob position (ranges from 0.0 to 1.0) + @param aProportion the knob's proportion (ranges from 0.0 to 1.0) +*/ +- (void)setFloatValue:(float)aValue knobProportion:(float)aProportion +{ + [self setFloatValue:aValue]; + [self setKnobProportion:aProportion]; +} + +@end diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index 72efe57a9..57e7033a9 100644 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -191,7 +191,8 @@ [scroller setValue:knobColor forThemeAttribute:@"knob-color" inState:CPThemeStateVertical]; - [scroller setFloatValue:0.1 knobProportion:0.5]; + [scroller setFloatValue:0.1]; + [scroller setKnobProportion:0.5]; return scroller; } @@ -234,10 +235,11 @@ [_CPCibCustomResource imageResourceWithName:"scroller-horizontal-knob-right.png" size:CGSizeMake(9.0, 15.0)] ] isVertical:NO]); - + [scroller setValue:knobColor forThemeAttribute:@"knob-color"]; - - [scroller setFloatValue:0.1 knobProportion:0.5]; + + [scroller setFloatValue:0.1]; + [scroller setKnobProportion:0.5]; return scroller; } diff --git a/Tools/nib2cib/NSScroller.j b/Tools/nib2cib/NSScroller.j index 1c39d70bd..5909d8d93 100644 --- a/Tools/nib2cib/NSScroller.j +++ b/Tools/nib2cib/NSScroller.j @@ -45,6 +45,8 @@ if ([aCoder containsValueForKey:"NSCurValue"]) _value = [aCoder decodeFloatForKey:"NSCurValue"]; + [self _calculateIsVertical]; + var isVertical = [self isVertical]; if (CPStringFromSelector([self action]) === @"_doScroller:")