From e4b29888645d4b64740d5382c516fc95fbb650fc Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 3 Feb 2009 22:47:02 -0800 Subject: [PATCH] Added more customizability. Reviewed by me. --- AppKit/CPButton.j | 256 ++++++++++------ AppKit/CPControl.h | 27 ++ AppKit/CPControl.j | 418 +++++++++++++++----------- AppKit/CPSlider.j | 59 +--- AppKit/CoreGraphics/CGGeometry.h | 5 + AppKit/CoreGraphics/CGGeometry.j | 4 + AppKit/Themes/Default/AppController.j | 4 +- AppKit/Themes/Default/Default.steam | 4 + AppKit/build.xml | 6 +- 9 files changed, 468 insertions(+), 315 deletions(-) create mode 100644 AppKit/CPControl.h diff --git a/AppKit/CPButton.j b/AppKit/CPButton.j index b167301c8..11aa24aee 100644 --- a/AppKit/CPButton.j +++ b/AppKit/CPButton.j @@ -25,6 +25,7 @@ @import "CPControl.j" +#include "CPControl.h" #include "CoreGraphics/CGGeometry.h" @@ -231,24 +232,33 @@ var _CPButtonClassName = nil, int _tag; int _state; BOOL _allowsMixedState; - BOOL _isHighlighted; CPImage _image; CPImage _alternateImage; - - CPCellImagePosition _imagePosition; - CPImageScaling _imageScaling; - + CPString _title; CPString _alternateTitle; + + CPControlStateValue _image; + CPControlStateValue _title; + // Display Properties + CPControlStateValue _bezelInset; + CPControlStateValue _contentInset; + + CPControlStateValue _bezelColor; + + // + CPView _bezelView; + _CPImageAndTextView _contentView; + + // NS-style Display Properties CPBezelStyle _bezelStyle; BOOL _isBordered; CPControlSize _controlSize; + // bleh BOOL _bezelBorderNeedsUpdate; - - _CPImageAndTextView _imageAndTextView; } /*! @@ -326,6 +336,14 @@ var _CPButtonClassName = nil, if (self) { + _bezelInset = [[CPControlStateValue alloc] initWithDefaultValue:_CGInsetMakeZero()]; + _contentInset = [[CPControlStateValue alloc] initWithDefaultValue:_CGInsetMakeZero()]; + + _bezelColor = [[CPControlStateValue alloc] initWithDefaultValue:nil]; + +// _image = [[CPControlStateValue alloc] initWithDefaultValue:nil]; +// _title = [[CPControlStateValue alloc] initWithDefaultValue:nil]; + [self setAlignment:CPCenterTextAlignment]; [self setVerticalAlignment:CPCenterVerticalTextAlignment]; [self setImagePosition:CPImageLeft]; @@ -340,50 +358,6 @@ var _CPButtonClassName = nil, return self; } -/*! - Sets the position of the button's image to anImagePosition. - @param anImagePosition the position for the button's image -*/ -- (void)setImagePosition:(CPCellImagePosition)anImagePosition -{ - [super setImagePosition:anImagePosition]; - - [_imageAndTextView setImagePosition:[self imagePosition]]; -} - -/*! - Sets the button's images scaling method - @param anImageScaling the image scaling method -*/ -- (void)setImageScaling:(CPImageScaling)anImageScaling -{ - [super setImageScaling:anImageScaling]; - - [_imageAndTextView setImageScaling:[self imageScaling]]; -} - -/*! - Sets the color of the button's text - @param aColor the color to use for drawing the button text -*/ -- (void)setTextColor:(CPColor)aColor -{ - [super setTextColor:aColor]; - - [_imageAndTextView setTextColor:[self textColor]]; -} - -/*! - Sets the font that will be used to draw the button text - @param aFont the font used to draw the button text -*/ -- (void)setFont:(CPFont)aFont -{ - [super setFont:aFont]; - - [_imageAndTextView setFont:[self font]]; -} - // Setting the state /*! Returns YES if the button has a 'mixed' state in addition to on and off. @@ -431,17 +405,6 @@ var _CPButtonClassName = nil, return _state; } -/*! - Sets the alignment of the text on the button. - @param anAlignment an alignment object -*/ -- (void)setAlignment:(CPTextAlignment)anAlignment -{ - [super setAlignment:anAlignment]; - - [_imageAndTextView setAlignment:[self alignment]]; -} - /*! Sets the image that will be drawn on the button. @param anImage the image that will be drawn @@ -507,7 +470,7 @@ var _CPButtonClassName = nil, Lays out the button. */ - (void)tile -{ +{return; var size = [self bounds].size; if (_isBordered) @@ -559,34 +522,19 @@ var _CPButtonClassName = nil, return bounds; } -- (void)drawRect:(CGRect)aRect -{ - if (!_imageAndTextView) - { - _imageAndTextView = [[_CPImageAndTextView alloc] initWithFrame:[self contentRectForBounds:[self bounds]] control:self]; - - [self addSubview:_imageAndTextView]; - } - else - [_imageAndTextView setFrame:[self contentRectForBounds:[self bounds]]]; - - [_imageAndTextView setText:_isHighlighted && _alternateTitle ? _alternateTitle : _title]; - [_imageAndTextView setImage:_isHighlighted && _alternateImage ? _alternateImage : _image]; -} - /*! Compacts the button's frame to fit its contents. */ - (void)sizeToFit -{ if (!_imageAndTextView) +{return; if (!_imageAndTextView) { _imageAndTextView = [[_CPImageAndTextView alloc] initWithFrame:[self contentRectForBounds:[self bounds]] control:self]; [self addSubview:_imageAndTextView]; } - [_imageAndTextView setText:_isHighlighted && _alternateTitle ? _alternateTitle : _title]; - [_imageAndTextView setImage:_isHighlighted && _alternateImage ? _alternateImage : _image]; + [_imageAndTextView setText:[self isHighlighted] && _alternateTitle ? _alternateTitle : _title]; + [_imageAndTextView setImage:[self isHighlighted] && _alternateImage ? _alternateImage : _image]; [_imageAndTextView sizeToFit]; @@ -610,10 +558,9 @@ var _CPButtonClassName = nil, */ - (void)highlight:(BOOL)aFlag { - _isHighlighted = aFlag; + [super highlight:aFlag]; [self drawBezelWithHighlight:aFlag]; - [self setNeedsDisplay:YES]; } /*! @@ -658,7 +605,7 @@ var _CPButtonClassName = nil, _controlSize = aControlSize; - [self drawBezelWithHighlight:_isHighlighted]; + [self drawBezelWithHighlight:[self isHighlighted]]; [self _updateTextAttributes]; } @@ -682,7 +629,7 @@ var _CPButtonClassName = nil, _isBordered = isBordered; [self updateBackgroundColors]; - [self drawBezelWithHighlight:_isHighlighted]; + [self drawBezelWithHighlight:[self isHighlighted]]; [self tile]; } @@ -723,7 +670,7 @@ var _CPButtonClassName = nil, _bezelStyle = aBezelStyle; [self updateBackgroundColors]; - [self drawBezelWithHighlight:_isHighlighted]; + [self drawBezelWithHighlight:[self isHighlighted]]; [self _updateTextAttributes]; [self tile]; @@ -739,7 +686,7 @@ var _CPButtonClassName = nil, /* @ignore */ - (void)updateBackgroundColors -{ +{return; if (_isBordered) { [self setBackgroundColor:_CPControlThreePartImagePattern( @@ -766,7 +713,7 @@ var _CPButtonClassName = nil, /* @ignore */ - (void)drawBezelWithHighlight:(BOOL)shouldHighlight -{ +{ return; _bezelBorderNeedsUpdate = ![self window]; if (_bezelBorderNeedsUpdate) @@ -778,12 +725,12 @@ var _CPButtonClassName = nil, - (void)viewDidMoveToWindow { if (_bezelBorderNeedsUpdate) - [self drawBezelWithHighlight:_isHighlighted]; + [self drawBezelWithHighlight:[self isHighlighted]]; } /* @ignore */ - (void)_updateTextAttributes -{ +{return; if (_bezelStyle == CPHUDBezelStyle) [self setTextColor:CPHUDBezelStyleTextColor]; @@ -791,6 +738,131 @@ var _CPButtonClassName = nil, [self setFont:[CPFont systemFontOfSize:11.0]]; } +// NEW + +- (CPView)createBezelView +{ + var view = [[CPView alloc] initWithFrame:_CGRectMakeZero()]; + + [view setHitTests:NO]; + + return view; +} + +CONTROL_STATE_VALUE(BezelColor, bezelColor) + +- (CPView)createContentView +{ + var view = [[_CPImageAndTextView alloc] initWithFrame:_CGRectMakeZero()]; + + return view; +} + +CONTROL_STATE_VALUE(ContentInset, contentInset) +CONTROL_STATE_VALUE(BezelInset, bezelInset) + +- (CGRect)contentRectForBounds:(CGRect)bounds +{ + var contentInset = [self contentInset]; + + if (!contentInset) + return bounds; + + bounds.origin.x += contentInset.left; + bounds.origin.y += contentInset.top; + bounds.size.width -= contentInset.left + contentInset.right; + bounds.size.height -= contentInset.top + contentInset.bottom; + + return bounds; +} + +- (CGRect)bezelRectForBounds:(CFRect)bounds +{ + var bezelInset = [self bezelInset]; + + if (!_CGInsetIsEmpty(bezelInset)) + return bounds; + + bounds.origin.x += bezelInset.left; + bounds.origin.y += bezelInset.top; + bounds.size.width -= bezelInset.left + bezelInset.right; + bounds.size.height -= bezelInset.top + bezelInset.bottom; + + return bounds; +} + +- (void)layoutSubviews +{ + var bounds = [self bounds], + bezelRect = [self bezelRectForBounds:_CGRectMakeCopy(bounds)]; + + if (bezelRect && !_CGRectIsEmpty(bezelRect)) + { + if (!_bezelView) + { + _bezelView = [self createBezelView]; + + if (_bezelView) + [self addSubview:_bezelView positioned:CPWindowBelow relativeTo:_contentView]; + } + + if (_bezelView) + [_bezelView setFrame:bezelRect]; + } + else if (_bezelView) + { + [_bezelView removeFromSuperview]; + + _bezelView = nil; + } + + if (_bezelView) + { + [_bezelView setBackgroundColor:[self bezelColor]]; + } + + var contentRect = [self contentRectForBounds:bounds]; + + if (contentRect && !_CGRectIsEmpty(contentRect)) + { + if (!_contentView) + { + _contentView = [self createContentView]; + + if (_contentView) + [self addSubview:_contentView positioned:CPWindowAbove relativeTo:_bezelView]; + } + + if (_contentView) + [_contentView setFrame:contentRect]; + } + else if (_contentView) + { + [_contentView removeFromSuperview]; + + _contentView = nil; + } + + if (_contentView) + { + [_contentView setText:[self isHighlighted] && _alternateTitle ? _alternateTitle : _title]; + [_contentView setImage:[self isHighlighted] && _alternateImage ? _alternateImage : _image]; + + // [_imageAndTextView setText:[self titleForControlState:_title]]; + // [_imageAndTextView setImage:[self imageForControlState:_controlState]]; + + [_contentView setFont:[self font]]; + [_contentView setTextColor:[self textColor]]; + [_contentView setAlignment:[self alignment]]; + [_contentView setVerticalAlignment:[self verticalAlignment]]; + [_contentView setLineBreakMode:[self lineBreakMode]]; + [_contentView setTextShadowColor:[self textShadowColor]]; + [_contentView setTextShadowOffset:[self textShadowOffset]]; + [_contentView setImagePosition:[self imagePosition]]; + [_contentView setImageScaling:[self imageScaling]]; + } +} + @end @@ -844,8 +916,8 @@ var CPButtonImageKey = @"CPButtonImageKey", // should just automatically be created programmatically as needed. var actualSubviews = _subviews; - _subviews = [_subviews copy]; - [_subviews removeObjectIdenticalTo:_imageAndTextView]; +// _subviews = [_subviews copy]; +// [_subviews removeObjectIdenticalTo:_imageAndTextView]; [super encodeWithCoder:aCoder]; diff --git a/AppKit/CPControl.h b/AppKit/CPControl.h new file mode 100644 index 000000000..ea28d45e6 --- /dev/null +++ b/AppKit/CPControl.h @@ -0,0 +1,27 @@ +#define CONTROL_STATE_VALUE(VALUE, LOWERCASEVALUE) \ +- (void)set##VALUE:(id)aValue forControlState:(CPControlState)aControlState\ +{\ + var currentValue = [_##LOWERCASEVALUE valueForControlState:_controlState];\ + [_##LOWERCASEVALUE setValue:aValue forControlState:aControlState];\ + if ([_##LOWERCASEVALUE valueForControlState:_controlState] === currentValue)\ + return;\ + [self setNeedsDisplay:YES];\ + [self setNeedsLayout];\ +}\ +- (id)LOWERCASEVALUE##ForControlState:(CPControlState)aControlState\ +{\ + return [_##LOWERCASEVALUE valueForControlState:aControlState];\ +}\ +- (void)set##VALUE:(id)aValue\ +{\ + var currentValue = [_##LOWERCASEVALUE valueForControlState:_controlState];\ + [_##LOWERCASEVALUE setValue:aValue];\ + if ([_##LOWERCASEVALUE valueForControlState:_controlState] === currentValue)\ + return;\ + [self setNeedsDisplay:YES];\ + [self setNeedsLayout];\ +}\ +- (id)LOWERCASEVALUE\ +{\ + return [_##LOWERCASEVALUE valueForControlState:_controlState];\ +} diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index 87c1c0fb6..e0f78b14b 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -87,18 +87,6 @@ var CPControlBlackColor = [CPColor blackColor]; @implementation CPControl : CPView { id _value; - BOOL _isEnabled; - - // Display Properties - CPTextAlignment _alignment; - CPVerticalTextAlignment _verticalAlignment; - - CPLineBreakMode _lineBreakMode; - CPColor _textColor; - CPFont _font; - - CPCellImagePosition _imagePosition; - CPImageScaling _imageScaling; // Target-Action Support id _target; @@ -116,6 +104,22 @@ var CPControlBlackColor = [CPColor blackColor]; CPDictionary _backgroundColors; CPString _currentBackgroundColorName; + + // Properties + CPControlStateValue _alignment; + CPControlStateValue _verticalAlignment; + + CPControlStateValue _lineBreakMode; + CPControlStateValue _textColor; + CPControlStateValue _font; + + CPControlStateValue _textShadowColor; + CPControlStateValue _textShadowOffset; + + CPControlStateValue _imagePosition; + CPControlStateValue _imageScaling; + + CPControlState _controlState; } - (id)initWithFrame:(CGRect)aFrame @@ -124,16 +128,28 @@ var CPControlBlackColor = [CPColor blackColor]; if (self) { - [self setVerticalAlignment:CPTopVerticalTextAlignment]; + _controlState = CPControlStateNormal; + + _alignment = [[CPControlStateValue alloc] initWithDefaultValue:CPLeftTextAlignment]; + _verticalAlignment = [[CPControlStateValue alloc] initWithDefaultValue:CPTopVerticalTextAlignment]; + + _lineBreakMode = [[CPControlStateValue alloc] initWithDefaultValue:CPLeftTextAlignment]; + _textColor = [[CPControlStateValue alloc] initWithDefaultValue:[CPColor blackColor]]; + _font = [[CPControlStateValue alloc] initWithDefaultValue:[CPFont systemFontOfSize:12.0]]; + + _textShadowColor = [[CPControlStateValue alloc] initWithDefaultValue:nil]; + _textShadowOffset = [[CPControlStateValue alloc] initWithDefaultValue:CGSizeMake(0.0, 0.0)];; + + _imagePosition = [[CPControlStateValue alloc] initWithDefaultValue:CPImageLeft]; + _imageScaling = [[CPControlStateValue alloc] initWithDefaultValue:CPScaleToFit]; + + // _sendActionOn = CPLeftMouseUpMask; _trackingMouseDownFlags = 0; _isEnabled = YES; - [self setFont:[CPFont systemFontOfSize:12.0]]; - [self setTextColor:CPControlBlackColor]; - _backgroundColors = [CPDictionary dictionary]; } @@ -157,163 +173,6 @@ var CPControlBlackColor = [CPColor blackColor]; return _isEnabled; } -/*! - Sets the receiver's horizontal text alignment - @param anAlignment the receiver's alignment -*/ -- (void)setAlignment:(CPTextAlignment)anAlignment -{ - _alignment = anAlignment; -} - -/*! - Returns the receiver's horizontal text alignment -*/ -- (CPTextAlignment)alignment -{ - return _alignment; -} - -/*! - Sets the receiver's vertical text alignment - @param anAlignment the receiver's alignment -*/ -- (void)setVerticalAlignment:(CPVerticalTextAlignment)anAlignment -{ - _verticalAlignment = anAlignment; -} - -/*! - Returns the receiver's vertical text alignment -*/ -- (CPVerticalTextAlignment)verticalAlignment -{ - return _verticalAlignment; -} - -/*! - Sets the receiver's line break mode. - @param anAlignment the receiver's line break mode. -*/ -- (void)setLineBreakMode:(CPLineBreakMode)aLineBreakMode -{ - _lineBreakMode = aLineBreakMode; -} - -/*! - Returns the receiver's line break mode. -*/ -- (CPLineBreakMode)lineBreakMode -{ - return _lineBreakMode; -} - -/*! - Sets the color of the receiver's text. -*/ -- (void)setTextColor:(CPColor)aColor -{ - if (_textColor == aColor) - return; - - _textColor = aColor; - -#if PLATFORM(DOM) - _DOMElement.style.color = [aColor cssString]; -#endif -} - -/*! - Returns the color of the receiver's text -*/ -- (CPColor)textColor -{ - return _textColor; -} - -/*! - Sets the receiver's font - @param aFont the font for the receiver -*/ -- (void)setFont:(CPFont)aFont -{ - if (_font == aFont) - return; - - _font = aFont; - -#if PLATFORM(DOM) - _DOMElement.style.font = [_font ? _font : [CPFont systemFontOfSize:12.0] cssString]; -#endif -} - -/*! - Returns the receiver's font -*/ -- (CPFont)font -{ - return _font; -} - -/*! - Sets the position of the button's image to anImagePosition. - @param anImagePosition the position for the button's image -*/ -- (void)setImagePosition:(CPCellImagePosition)anImagePosition -{ - if (_imagePosition === anImagePosition) - return; - - _imagePosition = anImagePosition; -} - -/*! - Returns the buton's image position -*/ -- (CPCellImagePosition)imagePosition -{ - return _imagePosition; -} - -/*! - Sets the button's images scaling method - @param anImageScaling the image scaling method -*/ -- (void)setImageScaling:(CPImageScaling)anImageScaling -{ - if (_imageScaling === anImageScaling) - return; - - _imageScaling = anImageScaling; -} - -/*! - Returns the button's image scaling method -*/ -- (CPImageScaling)imageScaling -{ - return _imageScaling; -} - -/*! - Sets the shadow for the receiver's text. - @param aTextShadow the text shadow -*/ -- (void)setTextShadow:(CPShadow)aTextShadow -{ -#if PLATFORM(DOM) - _DOMElement.style.textShadow = [_textShadow = aTextShadow cssString]; -#endif -} - -/*! - Returns the receiver's text shadow -*/ -- (CPShadow)textShadow -{ - return _textShadow; -} - /*! Returns the receiver's target action */ @@ -713,6 +572,8 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey"; if (self) { + _controlState = CPControlStateNormal; + [self setObjectValue:[aCoder decodeObjectForKey:CPControlValueKey]]; if ([aCoder containsValueForKey:__Deprecated__CPImageViewImageKey]) @@ -856,3 +717,214 @@ function _CPControlThreePartImagePattern(isVertical, sizes, aClassName) return color; } +/// + +#include "CPControl.h" + +@implementation CPControl (BETTER) + +CONTROL_STATE_VALUE(Alignment, alignment) +CONTROL_STATE_VALUE(VerticalAlignment, verticalAlignment) +CONTROL_STATE_VALUE(LineBreakMode, lineBreakMode) +CONTROL_STATE_VALUE(TextColor, textColor) +CONTROL_STATE_VALUE(Font, font) +CONTROL_STATE_VALUE(TextShadowColor, textShadowColor) +CONTROL_STATE_VALUE(TextShadowOffset, textShadowOffset) +CONTROL_STATE_VALUE(ImagePosition, imagePosition) +CONTROL_STATE_VALUE(ImageScaling, imageScaling) + +- (int)controlState +{ + return _controlState; +} + +- (void)setEnabled:(BOOL)isEnabled +{ + if ((!(_controlState & CPControlStateDisabled)) === isEnabled) + return; + + if (isEnabled) + _controlState &= ~CPControlStateDisabled; + else + _controlState |= CPControlStateDisabled; + + [self setNeedsLayout]; + [self setNeedsDisplay:YES]; +} + +- (BOOL)isEnabled +{ + return !(_controlState & CPControlStateDisabled); +} + +- (void)highlight:(BOOL)shouldHighlight +{ + [self setHighlighted:shouldHighlight]; +} + +- (void)setHighlighted:(BOOL)isHighlighted +{ + if ((!!(_controlState & CPControlStateHighlighted)) === isHighlighted) + return; + + if (isHighlighted) + _controlState |= CPControlStateHighlighted; + else + _controlState &= ~CPControlStateHighlighted; + + [self setNeedsLayout]; + [self setNeedsDisplay:YES]; +} + +- (BOOL)isHighlighted +{ + return !!(_controlState & CPControlStateHighlighted); +} + +@end + +CPControlStateNormal = 0, +CPControlStateHighlighted = 1 << 0, +CPControlStateDisabled = 1 << 1, +CPControlStateSelected = 1 << 2, +CPControlStateDefault = 1 << 3; + +@implementation CPControlStateValue : CPObject +{ + id _defaultValue; + JSObject _values; + int _highestState; +} + +- (id)initWithDefaultValue:(id)aDefaultValue +{ + self = [super init]; + + if (self) + { + _defaultValue = aDefaultValue; + _values = {}; + _highestState = 0; + } + + return self; +} + +- (void)setDefaultValue:(id)aDefaultValue +{ + _defaultValue = aDefaultValue; +} + +- (id)valueForControlState:(CPControlState)aState +{ + var value = _values[aState]; + + // If we don't have a value, and we have a non-normal state... + if (value === undefined && aState > 0) + { + // If this is a composite state, retrieve what we can. + if (!(aState & (aState - 1))) + { + var state = 1; + + while (value === undefined && state < _highestState) + { + if (state & aState) + value = _values[state]; + + state << 1; + } + } + + // Still don't have a value? OK, let's use the normal value. + if (value === undefined && aState > 0) + value = _values[CPControlStateNormal]; + } + + return value || _defaultValue; +} + +- (void)setValue:(id)aValue +{ + _values = {}; + _values[CPControlStateNormal] = aValue; + _highestState = CPControlStateNormal; +} + +- (void)setValue:(id)aValue forControlState:(CPControlState)aState +{ + if (_highestState < aState) + _highestState = aState; + + _values[aState] = aValue; +} + +- (void)removeValueForControlState:(CPControlState)aState +{ + delete _values[aState]; + +// if (_highestState === aState) +// _highestState = nil; +} + +@end + +var CPControlStateValueStates = @"CPControlStateValueStates", + CPControlStateValueValues = @"CPControlStateValueValues"; + +@implementation CPControlStateValue (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super init]; + + if (self) + { + _values = {}; + _highestState = 0; + + var states = [aCoder decodeObjectForKey:CPControlStateValueStates]; + + if (states) + { + var values = [aCoder decodeObjectForKey:CPControlStateValueValues], + count = states.length; + + while (count--) + { + var state = states[count]; + + if (state > _highestState) + _highestState = state; + + _values[state] = values[count]; + } + } + } + + return self; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + var states = [], + values = []; + + for (state in _values) + { + if (!_values.hasOwnProperty(state)) + continue; + + states.push(state); + values.push(_values[state]); + } + + if (states.length) + { + [aCoder encodeObject:states forKey:CPControlStateValueStates]; + [aCoder encodeObject:values forKey:CPControlStateValueValues]; + } +} + +@end + diff --git a/AppKit/CPSlider.j b/AppKit/CPSlider.j index 909c22e39..fd55eee84 100644 --- a/AppKit/CPSlider.j +++ b/AppKit/CPSlider.j @@ -2,6 +2,7 @@ @import #include "CoreGraphics/CGGeometry.h" +#include "CPControl.h" @implementation CPSlider : CPControl @@ -13,14 +14,11 @@ CPColor _verticalTrackColor; // vertical-track-color CPColor _horizontalTrackColor; // horizontal-track-color - CPColor _knobColor; // knob-color - CPColor _highlightedKnobColor; // knob-color-highlighted + CPControlStateValue _knobColor; float _trackWidth; // track-width CGSize _knobSize; // knob-size - BOOL _isHighlighted; - CPView _trackView; CPView _knobView; } @@ -33,6 +31,8 @@ { _minValue = 0.0; _maxValue = 100.0; + + _knobColor = [[CPControlStateValue alloc] initWithDefaultValue:nil]; [self setObjectValue:50.0]; @@ -155,19 +155,6 @@ return bounds; } -- (void)setHighlightedKnobColor:(CPColor)aColor -{ - if (_highlightedKnobColor === aColor) - _highlightedKnobColor = aColor; - - _highlightedKnobColor = aColor; -} - -- (CPColor)highlightedKnobColor -{ - return _highlightedKnobColor; -} - - (void)setKnobSize:(CGSize)aKnobSize { if (_knobSize && (!aKnobSize || _CGSizeEqualToSize(_knobSize, aKnobSize))) @@ -179,21 +166,7 @@ [self setNeedsDisplay:YES]; } -- (void)setKnobColor:(CPColor)aColor -{ - if (_knobColor === aColor) - return; - - _knobColor = aColor; - - [self setNeedsLayout]; - [self setNeedsDisplay:YES]; -} - -- (CPColor)knobColor -{ - return _knobColor; -} +CONTROL_STATE_VALUE(KnobColor, knobColor) - (CGRect)knobRectForBounds:(CGRect)bounds { @@ -303,13 +276,10 @@ { [_knobView setFrame:knobRect]; - if (_isHighlighted) - { - if (_highlightedKnobColor) - [_knobView setBackgroundColor:_highlightedKnobColor]; - } - else if (_knobColor) - [_knobView setBackgroundColor:_knobColor]; + var knobColor = [self knobColor]; + + if (knobColor) + [_knobView setBackgroundColor:knobColor]; } } else if (_knobView) @@ -377,7 +347,7 @@ return NO; } - _isHighlighted = YES; + [self setHighlighted:YES]; [self setNeedsLayout]; [self setNeedsDisplay:YES]; @@ -394,7 +364,7 @@ - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp { - _isHighlighted = NO; + [self setHighlighted:NO]; if ([_target respondsToSelector:@selector(sliderDidFinish:)]) [_target sliderDidFinish:self]; @@ -427,10 +397,10 @@ if (!theme) return; - + + //_knobColor = [theme valueForKey:@"knob-color"]; + [self setKnobSize:[theme valueForKey:@"knob-size"]]; - [self setKnobColor:[theme valueForKey:@"knob-color"]]; - [self setHighlightedKnobColor:[theme valueForKey:@"knob-color-highlighted"]]; [self setTrackWidth:[theme valueForKey:@"track-width"]]; [self setHorizontalTrackColor:[theme valueForKey:@"horizontal-track-color"]]; @@ -446,7 +416,6 @@ [values setObject:_knobSize forKey:@"knob-size"]; [values setObject:_knobColor forKey:@"knob-color"]; - [values setObject:_highlightedKnobColor forKey:@"knob-color-highlighted"]; [values setObject:_trackWidth forKey:@"track-width"]; [values setObject:_verticalTrackColor forKey:@"vertical-track-color"]; [values setObject:_horizontalTrackColor forKey:@"horizontal-track-color"]; diff --git a/AppKit/CoreGraphics/CGGeometry.h b/AppKit/CoreGraphics/CGGeometry.h index d12c97fc1..7958ea172 100644 --- a/AppKit/CoreGraphics/CGGeometry.h +++ b/AppKit/CoreGraphics/CGGeometry.h @@ -59,6 +59,11 @@ #define _CGRectContainsPoint(aRect, aPoint) (aPoint.x >= _CGRectGetMinX(aRect) && aPoint.y >= _CGRectGetMinY(aRect) && aPoint.x < _CGRectGetMaxX(aRect) && aPoint.y < _CGRectGetMaxY(aRect)) +#define _CGInsetMake(_top, _left, _bottom, _right) { top:(_top), left:(_left), bottom:(_bottom), right:(_right) } +#define _CGInsetMakeCopy(anInset) _CGInsetMake(anInset.top, anInset.left, anInset.bottom, anInset.right) +#define _CGInsetMakeZero() _CGInsetMake(0, 0, 0, 0) +#define _CGInsetIsEmpty(anInset) ((anInset).left === 0 && (anInset).top === 0 && (anInset).right === 0 && (anInset).bottom === 0) + // DEPRECATED #define _CGPointCreateCopy(aPoint) _CGPointMake(aPoint.x, aPoint.y) #define _CGSizeCreateCopy(aSize) _CGSizeMake(aSize.width, aSize.height) diff --git a/AppKit/CoreGraphics/CGGeometry.j b/AppKit/CoreGraphics/CGGeometry.j index d9a07af7a..880202fb2 100644 --- a/AppKit/CoreGraphics/CGGeometry.j +++ b/AppKit/CoreGraphics/CGGeometry.j @@ -65,6 +65,10 @@ _function(CGRectIsNull(aRect)) _function(CGRectContainsPoint(aRect, aPoint)) +_function(CGInsetMake(top, left, bottom, right)) +_function(CGInsetMakeCopy(anInset)) +_function(CGInsetIsEmpty(anInset)) + /*! Returns a BOOL indicating whether CGRect lhsRect contains CGRect rhsRect. diff --git a/AppKit/Themes/Default/AppController.j b/AppKit/Themes/Default/AppController.j index 518cc25e4..54448b351 100644 --- a/AppKit/Themes/Default/AppController.j +++ b/AppKit/Themes/Default/AppController.j @@ -43,7 +43,7 @@ [horizontalSlider setKnobSize:CGSizeMake(12.0, 12.0)]; [horizontalSlider setKnobColor:knobColor]; - [horizontalSlider setHighlightedKnobColor:knobHighlightedColor]; + [horizontalSlider setKnobColor:knobHighlightedColor forControlState:CPControlStateHighlighted]; views.push(horizontalSlider); @@ -64,7 +64,7 @@ [verticalSlider setKnobSize:CGSizeMake(12.0, 12.0)]; [verticalSlider setKnobColor:knobColor]; - [verticalSlider setHighlightedKnobColor:knobHighlightedColor]; + [verticalSlider setKnobColor:knobHighlightedColor forControlState:CPControlStateHighlighted]; views.push(verticalSlider); diff --git a/AppKit/Themes/Default/Default.steam b/AppKit/Themes/Default/Default.steam index 367779c42..2d0b2e005 100644 --- a/AppKit/Themes/Default/Default.steam +++ b/AppKit/Themes/Default/Default.steam @@ -11,6 +11,10 @@ Default.cptheme Type 280N.theme + Excluded + + Frameworks + Configurations diff --git a/AppKit/build.xml b/AppKit/build.xml index fd1cf5001..6fa4b3521 100644 --- a/AppKit/build.xml +++ b/AppKit/build.xml @@ -19,7 +19,7 @@ - + @@ -27,11 +27,11 @@ - + - +