mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-05 12:15:32 +00:00
Further improvements.
Reviewed by me.
This commit is contained in:
1 parent
a30e91052e
commit
50baf5fd50
8 files changed
+405
-513
No files matched your search
+62
-120
@@ -27,7 +27,6 @@
|
||||
@import "CPThemedValue.j"
|
||||
|
||||
#include "CoreGraphics/CGGeometry.h"
|
||||
#include "CPThemedValue.h"
|
||||
|
||||
|
||||
CPScaleProportionally = 0;
|
||||
@@ -256,24 +255,23 @@ var _CPButtonClassName = nil,
|
||||
CPControlSize _controlSize;
|
||||
}
|
||||
|
||||
+ (id)themedAttributes
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMakeZero(), nil]
|
||||
forKeys:[@"bezel-inset", @"content-inset", @"bezel-color"]];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
{
|
||||
self = [super initWithFrame:aFrame];
|
||||
|
||||
if (self)
|
||||
{
|
||||
var theme = [self theme],
|
||||
theClass = [self class];
|
||||
|
||||
_bezelInset = CPThemedValueMake(_CGInsetMakeZero(), "bezel-inset", theme, theClass);
|
||||
_contentInset = CPThemedValueMake(_CGInsetMakeZero(), "content-inset", theme, theClass);
|
||||
|
||||
_bezelColor = CPThemedValueMake(nil, "bezel-color", theme, theClass);
|
||||
|
||||
[self setAlignment:CPCenterTextAlignment];
|
||||
[self setVerticalAlignment:CPCenterVerticalTextAlignment];
|
||||
[self setImagePosition:CPImageLeft];
|
||||
[self setImageScaling:CPScaleNone];
|
||||
// Should we instead override the defaults?
|
||||
[self setValue:CPCenterTextAlignment forThemedAttributeName:@"alignment"];
|
||||
[self setValue:CPCenterVerticalTextAlignment forThemedAttributeName:@"vertical-alignment"];
|
||||
[self setValue:CPImageLeft forThemedAttributeName:@"image-position"];
|
||||
[self setValue:CPScaleNone forThemedAttributeName:@"image-scaling"];
|
||||
|
||||
_controlSize = CPRegularControlSize;
|
||||
|
||||
@@ -464,8 +462,6 @@ var _CPButtonClassName = nil,
|
||||
return view;
|
||||
}
|
||||
|
||||
THEMED_STATED_VALUE(BezelColor, bezelColor)
|
||||
|
||||
- (CPView)createContentView
|
||||
{
|
||||
var view = [[_CPImageAndTextView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
@@ -473,16 +469,13 @@ THEMED_STATED_VALUE(BezelColor, bezelColor)
|
||||
return view;
|
||||
}
|
||||
|
||||
THEMED_STATED_VALUE(ContentInset, contentInset)
|
||||
THEMED_STATED_VALUE(BezelInset, bezelInset)
|
||||
|
||||
- (CGRect)contentRectForBounds:(CGRect)bounds
|
||||
{
|
||||
if (![self isBordered])
|
||||
return bounds;
|
||||
|
||||
var contentInset = [self currentContentInset];
|
||||
|
||||
var contentInset = [self currentValueForThemedAttributeName:@"content-inset"];
|
||||
|
||||
if (!contentInset)
|
||||
return bounds;
|
||||
|
||||
@@ -499,7 +492,7 @@ THEMED_STATED_VALUE(BezelInset, bezelInset)
|
||||
if (![self isBordered])
|
||||
return _CGRectMakeZero();
|
||||
|
||||
var bezelInset = [self currentBezelInset];
|
||||
var bezelInset = [self currentValueForThemedAttributeName:@"bezel-inset"];
|
||||
|
||||
if (!_CGInsetIsEmpty(bezelInset))
|
||||
return bounds;
|
||||
@@ -512,106 +505,65 @@ THEMED_STATED_VALUE(BezelInset, bezelInset)
|
||||
return bounds;
|
||||
}
|
||||
|
||||
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
|
||||
{
|
||||
if (aName === "bezel-view")
|
||||
return [self bezelRectForBounds:[self bounds]];
|
||||
|
||||
else if (aName === "content-view")
|
||||
return [self contentRectForBounds:[self bounds]];
|
||||
|
||||
return [super rectForEphemeralSubviewNamed:aName];
|
||||
}
|
||||
|
||||
- (CPView)createEphemeralSubviewNamed:(CPString)aName
|
||||
{
|
||||
if (aName === "bezel-view")
|
||||
{
|
||||
var view = [[CPView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
|
||||
[view setHitTests:NO];
|
||||
|
||||
return view;
|
||||
}
|
||||
else
|
||||
return [[_CPImageAndTextView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
|
||||
return [super createEphemeralSubviewNamed:aName];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
var bounds = [self bounds],
|
||||
bezelRect = [self bezelRectForBounds:_CGRectMakeCopy(bounds)];
|
||||
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
|
||||
positioned:CPWindowBelow
|
||||
relativeToEphemeralSubviewNamed:@"content-view"];
|
||||
|
||||
if (bezelView)
|
||||
[bezelView setBackgroundColor:[self currentValueForThemedAttributeName:@"bezel-color"]];
|
||||
|
||||
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;
|
||||
}
|
||||
var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
|
||||
positioned:CPWindowAbove
|
||||
relativeToEphemeralSubviewNamed:@"bezel-view"];
|
||||
|
||||
if (_bezelView)
|
||||
if (contentView)
|
||||
{
|
||||
[_bezelView setBackgroundColor:[self currentBezelColor]];
|
||||
}
|
||||
[contentView setText:((_controlState & CPControlStateHighlighted) && _alternateTitle) ? _alternateTitle : _title];
|
||||
[contentView setImage:((_controlState & CPControlStateHighlighted) && _alternateImage) ? _alternateImage : _image];
|
||||
|
||||
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:((_controlState & CPControlStateHighlighted) && _alternateTitle) ? _alternateTitle : _title];
|
||||
[_contentView setImage:((_controlState & CPControlStateHighlighted) && _alternateImage) ? _alternateImage : _image];
|
||||
|
||||
[_contentView setFont:[self currentFont]];
|
||||
[_contentView setTextColor:[self currentTextColor]];
|
||||
[_contentView setAlignment:[self currentAlignment]];
|
||||
[_contentView setVerticalAlignment:[self currentVerticalAlignment]];
|
||||
[_contentView setLineBreakMode:[self currentLineBreakMode]];
|
||||
[_contentView setTextShadowColor:[self currentTextShadowColor]];
|
||||
[_contentView setTextShadowOffset:[self currentTextShadowOffset]];
|
||||
[_contentView setImagePosition:[self currentImagePosition]];
|
||||
[_contentView setImageScaling:[self currentImageScaling]];
|
||||
[contentView setFont:[self currentValueForThemedAttributeName:@"font"]];
|
||||
[contentView setTextColor:[self currentValueForThemedAttributeName:@"text-color"]];
|
||||
[contentView setAlignment:[self currentValueForThemedAttributeName:@"alignment"]];
|
||||
[contentView setVerticalAlignment:[self currentValueForThemedAttributeName:@"vertical-alignment"]];
|
||||
[contentView setLineBreakMode:[self currentValueForThemedAttributeName:@"line-break-mode"]];
|
||||
[contentView setTextShadowColor:[self currentValueForThemedAttributeName:@"text-shadow-color"]];
|
||||
[contentView setTextShadowOffset:[self currentValueForThemedAttributeName:@"text-shadow-offset"]];
|
||||
[contentView setImagePosition:[self currentValueForThemedAttributeName:@"image-position"]];
|
||||
[contentView setImageScaling:[self currentValueForThemedAttributeName:@"image-scaling"]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPButton (Theming)
|
||||
|
||||
- (void)viewDidChangeTheme
|
||||
{
|
||||
[super viewDidChangeTheme];
|
||||
|
||||
var theme = [self theme];
|
||||
|
||||
[_bezelInset setTheme:theme];
|
||||
[_contentInset setTheme:theme];
|
||||
|
||||
[_bezelColor setTheme:theme];
|
||||
}
|
||||
|
||||
- (CPDictionary)themedValues
|
||||
{
|
||||
var values = [super themedValues];
|
||||
|
||||
[values setObject:_bezelInset forKey:@"bezel-inset"];
|
||||
[values setObject:_contentInset forKey:@"content-inset"];
|
||||
|
||||
[values setObject:_bezelColor forKey:@"bezel-color"];
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CPButton (NS)
|
||||
|
||||
- (void)setBezelStyle:(unsigned)aBezelStyle
|
||||
@@ -677,11 +629,6 @@ var CPButtonImageKey = @"CPButtonImageKey",
|
||||
|
||||
[self setTitle:[aCoder decodeObjectForKey:CPButtonTitleKey]];
|
||||
[self setAlternateTitle:[aCoder decodeObjectForKey:CPButtonAlternateTitleKey]];
|
||||
|
||||
_contentInset = CPThemedValueDecode(aCoder, CPButtonContentInsetKey, _CGInsetMakeZero(), @"content-inset", theme, theClass);
|
||||
_bezelInset = CPThemedValueDecode(aCoder, CPButtonBezelInsetKey, _CGInsetMakeZero(), @"bezel-inset", theme, theClass);
|
||||
|
||||
_bezelColor = CPThemedValueDecode(aCoder, CPButtonBezelColorKey, nil, @"bezel-color", theme, theClass);
|
||||
|
||||
_isBordered = [aCoder decodeBoolForKey:CPButtonIsBorderedKey];
|
||||
|
||||
@@ -717,11 +664,6 @@ var CPButtonImageKey = @"CPButtonImageKey",
|
||||
|
||||
[aCoder encodeBool:_isBordered forKey:CPButtonIsBorderedKey];
|
||||
[aCoder encodeInt:_bezelStyle forKey:CPButtonBezelStyleKey];
|
||||
|
||||
CPThemedValueEncode(aCoder, CPButtonContentInsetKey, _contentInset);
|
||||
CPThemedValueEncode(aCoder, CPButtonBezelInsetKey, _bezelInset);
|
||||
|
||||
CPThemedValueEncode(aCoder, CPButtonBezelColorKey, _bezelColor);
|
||||
}
|
||||
|
||||
@end
|
||||
+88
-128
@@ -26,7 +26,6 @@
|
||||
@import "CPThemedValue.j"
|
||||
|
||||
#include "CoreGraphics/CGGeometry.h"
|
||||
#include "CPThemedValue.h"
|
||||
#include "Platform/Platform.h"
|
||||
|
||||
/*
|
||||
@@ -101,26 +100,22 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
unsigned _trackingMouseDownFlags;
|
||||
CGPoint _previousTrackingLocation;
|
||||
|
||||
// Properties
|
||||
CPThemedValue _alignment;
|
||||
CPThemedValue _verticalAlignment;
|
||||
|
||||
CPControlStateValue _lineBreakMode;
|
||||
CPControlStateValue _textColor;
|
||||
CPControlStateValue _font;
|
||||
|
||||
CPControlStateValue _textShadowColor;
|
||||
CPControlStateValue _textShadowOffset;
|
||||
|
||||
CPControlStateValue _imagePosition;
|
||||
CPControlStateValue _imageScaling;
|
||||
|
||||
CPControlState _controlState;
|
||||
|
||||
JSObject _ephemeralSubviewsForNames;
|
||||
CPSet _ephereralSubviews;
|
||||
|
||||
// FIXME: Who uses this?
|
||||
BOOL _isBezeled;
|
||||
}
|
||||
|
||||
+ (CPDictionary)themedAttributes
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[
|
||||
CPLeftTextAlignment, CPTopVerticalTextAlignment, CPLineBreakByClipping, [CPColor blackColor], [CPFont systemFontOfSize:12.0], nil, _CGSizeMakeZero(), CPImageLeft, CPScaleToFit]
|
||||
forKeys:[@"alignment", @"vertical-alignment", @"line-break-mode", @"text-color", @"font", @"text-shadow-color", @"text-shadow-offset", @"image-position", @"image-scaling"]];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
{
|
||||
self = [super initWithFrame:aFrame];
|
||||
@@ -128,26 +123,7 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
if (self)
|
||||
{
|
||||
_controlState = CPControlStateNormal;
|
||||
|
||||
var theme = [self theme],
|
||||
theClass = [self class];
|
||||
|
||||
_alignment = CPThemedValueMake(CPLeftTextAlignment, "alignment", theme, theClass);
|
||||
_verticalAlignment = CPThemedValueMake(CPTopVerticalTextAlignment, "vertical-alignment", theme, theClass);
|
||||
|
||||
_lineBreakMode = CPThemedValueMake(CPLineBreakByClipping, "line-break-mode", theme, theClass);
|
||||
_textColor = CPThemedValueMake([CPColor blackColor], "text-color", theme, theClass);
|
||||
_font = CPThemedValueMake([CPFont systemFontOfSize:12.0], "font", theme, theClass);
|
||||
|
||||
_textShadowColor = CPThemedValueMake(nil, @"text-shadow-color", theme, theClass);
|
||||
_textShadowOffset = CPThemedValueMake(_CGSizeMake(0.0, 0.0), "text-shadow-offset", theme, theClass);
|
||||
|
||||
_imagePosition = CPThemedValueMake(CPImageLeft, @"image-position", theme, theClass);
|
||||
_imageScaling = CPThemedValueMake(CPScaleToFit, "image-scaling", theme, theClass);
|
||||
|
||||
[theme setActiveClass:nil];
|
||||
//
|
||||
|
||||
|
||||
_sendActionOn = CPLeftMouseUpMask;
|
||||
_trackingMouseDownFlags = 0;
|
||||
}
|
||||
@@ -478,15 +454,25 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPControlTextDidEndEditingNotification object:self userInfo:[CPDictionary dictionaryWithObject:[note object] forKey:"CPFieldEditor"]];
|
||||
}
|
||||
|
||||
THEMED_STATED_VALUE(Alignment, alignment)
|
||||
THEMED_STATED_VALUE(VerticalAlignment, verticalAlignment)
|
||||
THEMED_STATED_VALUE(LineBreakMode, lineBreakMode)
|
||||
THEMED_STATED_VALUE(TextColor, textColor)
|
||||
THEMED_STATED_VALUE(Font, font)
|
||||
THEMED_STATED_VALUE(TextShadowColor, textShadowColor)
|
||||
THEMED_STATED_VALUE(TextShadowOffset, textShadowOffset)
|
||||
THEMED_STATED_VALUE(ImagePosition, imagePosition)
|
||||
THEMED_STATED_VALUE(ImageScaling, imageScaling)
|
||||
#define BRIDGE(UPPERCASE, LOWERCASE, ATTRIBUTENAME) \
|
||||
- (void)set##UPPERCASE:(id)aValue\
|
||||
{\
|
||||
[self setValue:aValue forThemedAttributeName:ATTRIBUTENAME];\
|
||||
}\
|
||||
- (id)LOWERCASE\
|
||||
{\
|
||||
return [self valueForThemedAttributeName:ATTRIBUTENAME];\
|
||||
}
|
||||
|
||||
BRIDGE(Alignment, alignment, "alignment")
|
||||
BRIDGE(VerticalAlignment, verticalAlignment, "vertical-alignment")
|
||||
BRIDGE(LineBreakMode, lineBreakMode, "line-break-mode")
|
||||
BRIDGE(TextColor, textColor, "text-color")
|
||||
BRIDGE(Font, font, "font")
|
||||
BRIDGE(TextShadowColor, textShadowColor, "text-shadow-color")
|
||||
BRIDGE(TextShadowOffset, textShadowOffset, "text-shadow-offset")
|
||||
BRIDGE(ImagePosition, imagePosition, "image-position")
|
||||
BRIDGE(ImageScaling, imageScaling, "image-scaling")
|
||||
|
||||
- (int)controlState
|
||||
{
|
||||
@@ -536,48 +522,52 @@ THEMED_STATED_VALUE(ImageScaling, imageScaling)
|
||||
return !!(_controlState & CPControlStateHighlighted);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPControl (Theming)
|
||||
|
||||
- (void)viewDidChangeTheme
|
||||
- (CPView)createEphemeralSubviewNamed:(CPString)aViewName
|
||||
{
|
||||
[super viewDidChangeTheme];
|
||||
|
||||
var theme = [self theme];
|
||||
|
||||
[_alignment setTheme:theme];
|
||||
[_verticalAlignment setTheme:theme];
|
||||
|
||||
[_lineBreakMode setTheme:theme];
|
||||
[_textColor setTheme:theme];
|
||||
[_font setTheme:theme];
|
||||
|
||||
[_textShadowColor setTheme:theme];
|
||||
[_textShadowOffset setTheme:theme];
|
||||
|
||||
[_imagePositions setTheme:theme];
|
||||
[_imageScaling setTheme:theme];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (CPDictionary)themedValues
|
||||
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aViewName
|
||||
{
|
||||
var values = [super themedValues];
|
||||
return _CGRectMakeZero();
|
||||
}
|
||||
|
||||
[values setObject:_alignment forKey:@"alignment"];
|
||||
[values setObject:_verticalAlignment forKey:@"vertical-alignment"];
|
||||
- (CPView)layoutEphemeralSubviewNamed:(CPString)aViewName
|
||||
positioned:(CPWindowOrderingMode)anOrderingMode
|
||||
relativeToEphemeralSubviewNamed:(CPString)relativeToViewName
|
||||
{
|
||||
if (!_ephemeralSubviewsForNames)
|
||||
{
|
||||
_ephemeralSubviewsForNames = {};
|
||||
_ephemeralSubviews = [CPSet set];
|
||||
}
|
||||
|
||||
[values setObject:_lineBreakMode forKey:@"line-break-mode"];
|
||||
[values setObject:_textColor forKey:@"text-color"];
|
||||
[values setObject:_font forKey:@"font"];
|
||||
|
||||
[values setObject:_textShadowColor forKey:@"text-shadow-color"];
|
||||
[values setObject:_textShadowOffset forKey:@"text-shadow-offset"];
|
||||
|
||||
[values setObject:_imagePosition forKey:@"image-position"];
|
||||
[values setObject:_imageScaling forKey:@"image-scaling"];
|
||||
var frame = [self rectForEphemeralSubviewNamed:aViewName];
|
||||
|
||||
return values;
|
||||
if (frame && !_CGRectIsEmpty(frame))
|
||||
{
|
||||
if (!_ephemeralSubviewsForNames[aViewName])
|
||||
{
|
||||
_ephemeralSubviewsForNames[aViewName] = [self createEphemeralSubviewNamed:aViewName];
|
||||
|
||||
[_ephemeralSubviews addObject:_ephemeralSubviewsForNames[aViewName]];
|
||||
|
||||
if (_ephemeralSubviewsForNames[aViewName])
|
||||
[self addSubview:_ephemeralSubviewsForNames[aViewName] positioned:anOrderingMode relativeTo:_ephemeralSubviewsForNames[relativeToViewName]];
|
||||
}
|
||||
|
||||
if (_ephemeralSubviewsForNames[aViewName])
|
||||
[_ephemeralSubviewsForNames[aViewName] setFrame:frame];
|
||||
}
|
||||
else if (_ephemeralSubviewsForNames[aViewName])
|
||||
{
|
||||
[_ephemeralSubviewsForNames[aViewName] removeFromSuperview];
|
||||
|
||||
[_ephemeralSubviews removeObject:_ephemeralSubviewsForNames[aViewName]];
|
||||
delete _ephemeralSubviewsForNames[aViewName];
|
||||
}
|
||||
|
||||
return _ephemeralSubviewsForNames[aViewName];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -585,16 +575,6 @@ THEMED_STATED_VALUE(ImageScaling, imageScaling)
|
||||
var CPControlValueKey = "CPControlValueKey",
|
||||
CPControlIsEnabledKey = "CPControlIsEnabledKey",
|
||||
|
||||
CPControlAlignmentKey = @"CPControlAlignmentKey",
|
||||
CPControlVerticalAlignmentKey = @"CPControlVerticalAlignmentKey",
|
||||
CPControlLineBreakModeKey = @"CPControlLineBreakModeKey",
|
||||
CPControlFontKey = @"CPControlFontKey",
|
||||
CPControlTextColorKey = @"CPControlTextColorKey",
|
||||
CPControlTextShadowColorKey = @"CPControlTextShadowColorKey",
|
||||
CPControlTextShadowOffsetKey = @"CPControlTextShadowOffsetKey",
|
||||
CPControlImagePositionKey = @"CPControlImagePositionKey",
|
||||
CPControlImageScalingKey = @"CPControlImageScalingKey",
|
||||
|
||||
CPControlTargetKey = "CPControlTargetKey",
|
||||
CPControlActionKey = "CPControlActionKey",
|
||||
CPControlSendActionOnKey = "CPControlSendActionOnKey";
|
||||
@@ -616,24 +596,8 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey";
|
||||
{
|
||||
_controlState = CPControlStateNormal;
|
||||
|
||||
var theme = [self theme],
|
||||
theClass = [self class];
|
||||
|
||||
[self setObjectValue:[aCoder decodeObjectForKey:CPControlValueKey]];
|
||||
|
||||
_alignment = CPThemedValueDecode(aCoder, CPControlAlignmentKey, CPLeftTextAlignment, @"alignment", theme, theClass);
|
||||
_verticalAlignment = CPThemedValueDecode(aCoder, CPControlVerticalAlignmentKey, CPTopVerticalTextAlignment, @"vertical-alignment", theme, theClass);
|
||||
|
||||
_lineBreakMode = CPThemedValueDecode(aCoder, CPControlLineBreakModeKey, CPLineBreakByClipping, @"line-break-mode", theme, theClass);
|
||||
_textColor = CPThemedValueDecode(aCoder, CPControlTextColorKey, [CPColor blackColor], @"text-color", theme, theClass);
|
||||
_font = CPThemedValueDecode(aCoder, CPControlFontKey, [CPFont systemFontOfSize:12.0], @"font", theme, theClass);
|
||||
|
||||
_textShadowColor = CPThemedValueDecode(aCoder, CPControlTextShadowColorKey, nil, @"text-shadow-color", theme, theClass);
|
||||
_textShadowOffset = CPThemedValueDecode(aCoder, CPControlTextShadowOffsetKey, _CGSizeMake(0.0, 0.0), @"text-shadow-offset", theme, theClass);
|
||||
|
||||
_imagePosition = CPThemedValueDecode(aCoder, CPControlImagePositionKey, CPImageLeft, @"image-position", theme, theClass);
|
||||
_imageScaling = CPThemedValueDecode(aCoder, CPControlImageScalingKey, CPScaleToFit, @"image-scaling", theme, theClass);
|
||||
|
||||
|
||||
/*
|
||||
[self setTarget:[aCoder decodeObjectForKey:CPControlTargetKey]];
|
||||
[self setAction:[aCoder decodeObjectForKey:CPControlActionKey]];
|
||||
@@ -649,32 +613,28 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey";
|
||||
*/
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
var count = [_subviews count],
|
||||
ephemeral
|
||||
subviews = nil;
|
||||
|
||||
if (count > 0 && [_ephemeralSubviews count] > 0)
|
||||
{
|
||||
subviews = [_subviews.slice(0) copy];
|
||||
|
||||
while (count--)
|
||||
if ([_ephemeralSubviews containsObject:_subviews[count]])
|
||||
_subviews.splice(count, 1);
|
||||
}
|
||||
|
||||
[super encodeWithCoder:aCoder];
|
||||
|
||||
if (subviews)
|
||||
_subviews = subviews;
|
||||
|
||||
[aCoder encodeObject:_value forKey:CPControlValueKey];
|
||||
|
||||
CPThemedValueEncode(aCoder, CPControlAlignmentKey, _alignment);
|
||||
CPThemedValueEncode(aCoder, CPControlVerticalAlignmentKey, _verticalAlignment);
|
||||
|
||||
CPThemedValueEncode(aCoder, CPControlLineBreakModeKey, _lineBreakMode);
|
||||
CPThemedValueEncode(aCoder, CPControlTextColorKey, _textColor);
|
||||
CPThemedValueEncode(aCoder, CPControlFontKey, _font);
|
||||
|
||||
CPThemedValueEncode(aCoder, CPControlTextShadowColorKey, _textShadowColor);
|
||||
CPThemedValueEncode(aCoder, CPControlTextShadowOffsetKey, _textShadowOffset);
|
||||
|
||||
CPThemedValueEncode(aCoder, CPControlImagePositionKey, _imagePosition);
|
||||
CPThemedValueEncode(aCoder, CPControlImageScalingKey, _imageScaling);
|
||||
|
||||
/*
|
||||
[aCoder encodeBool:_isEnabled forKey:CPControlIsEnabledKey];
|
||||
|
||||
[aCoder encodeInt:_alignment forKey:CPControlAlignmentKey];
|
||||
[aCoder encodeInt:_verticalAlignment forKey:CPControlVerticalAlignmentKey];
|
||||
|
||||
[aCoder encodeObject:_font forKey:CPControlFontKey];
|
||||
[aCoder encodeObject:_textColor forKey:CPControlTextColorKey];
|
||||
|
||||
/*[aCoder encodeBool:_isEnabled forKey:CPControlIsEnabledKey];
|
||||
|
||||
[aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
|
||||
[aCoder encodeObject:_action forKey:CPControlActionKey];
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ var LEFT_SHADOW_INSET = 3.0,
|
||||
[super setImageScaling:anImageScaling];
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
if ([self currentImageScaling] === CPScaleToFit)
|
||||
if ([self currentValueForThemedAttributeName:@"image-scaling"] === CPScaleToFit)
|
||||
{
|
||||
CPDOMDisplayServerSetStyleLeftTop(_DOMImageElement, NULL, 0.0, 0.0);
|
||||
}
|
||||
@@ -254,6 +254,7 @@ var LEFT_SHADOW_INSET = 3.0,
|
||||
|
||||
var bounds = [self bounds],
|
||||
image = [self image],
|
||||
imageScaling = [self currentValueForThemedAttributeName:@"image-scaling"],
|
||||
x = 0.0,
|
||||
y = 0.0,
|
||||
insetWidth = (_hasShadow ? HORIZONTAL_SHADOW_INSET : 0.0),
|
||||
@@ -262,8 +263,8 @@ var LEFT_SHADOW_INSET = 3.0,
|
||||
boundsHeight = _CGRectGetHeight(bounds),
|
||||
width = boundsWidth - insetWidth,
|
||||
height = boundsHeight - insetHeight;
|
||||
|
||||
if (_imageScaling == CPScaleToFit)
|
||||
|
||||
if (imageScaling === CPScaleToFit)
|
||||
{
|
||||
#if PLATFORM(DOM)
|
||||
_DOMImageElement.width = ROUND(width);
|
||||
@@ -277,7 +278,7 @@ var LEFT_SHADOW_INSET = 3.0,
|
||||
if (size.width == -1 && size.height == -1)
|
||||
return;
|
||||
|
||||
if (_imageScaling == CPScaleProportionally)
|
||||
if (imageScaling === CPScaleProportionally)
|
||||
{
|
||||
// The max size it can be is size.width x size.height, so only
|
||||
// only proportion otherwise.
|
||||
@@ -308,7 +309,7 @@ var LEFT_SHADOW_INSET = 3.0,
|
||||
height = size.height;
|
||||
}
|
||||
|
||||
if (_imageScaling == CPScaleNone)
|
||||
if (imageScaling == CPScaleNone)
|
||||
{
|
||||
#if PLATFORM(DOM)
|
||||
_DOMImageElement.width = ROUND(size.width);
|
||||
|
||||
@@ -61,9 +61,9 @@ var CPPopUpButtonArrowsImage = nil;
|
||||
_selectedIndex = CPNotFound;
|
||||
_preferredEdge = CPMaxYEdge;
|
||||
|
||||
[self setImagePosition:CPImageLeft];
|
||||
[self setAlignment:CPLeftTextAlignment];
|
||||
[self setLineBreakMode:CPLineBreakByTruncatingTail];
|
||||
[self setValue:CPImageLeft forThemedAttributeName:@"image-position"];
|
||||
[self setValue:CPLeftTextAlignment forThemedAttributeName:@"alignment"];
|
||||
[self setValue:CPLineBreakByTruncatingTail forThemedAttributeName:@"line-break-mode"];
|
||||
|
||||
[self setMenu:[[CPMenu alloc] initWithTitle:@""]];
|
||||
}
|
||||
@@ -708,7 +708,7 @@ var CPPopUpButtonArrowsImage = nil;
|
||||
|
||||
if ([self isBordered])
|
||||
{
|
||||
contentRect.size.width -= 16.0;
|
||||
contentRect.size.width -= 20.0;
|
||||
|
||||
return contentRect;
|
||||
}
|
||||
|
||||
+10
-8
@@ -161,8 +161,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
[_verticalScroller setEnabled:NO];
|
||||
[_horizontalScroller setEnabled:NO];
|
||||
// [_verticalScroller setEnabled:NO];
|
||||
// [_horizontalScroller setEnabled:NO];
|
||||
}
|
||||
|
||||
[_contentView setFrame:[self bounds]];
|
||||
@@ -180,22 +180,24 @@
|
||||
shouldShowHorizontalScroller = (!_autohidesScrollers || difference.width > 0.0) && _hasHorizontalScroller,
|
||||
wasShowingVerticalScroller = ![_verticalScroller isHidden],
|
||||
wasShowingHorizontalScroller = ![_horizontalScroller isHidden],
|
||||
verticalScrollerWidth = [CPScroller scrollerWidthForControlSize:[_verticalScroller controlSize]],
|
||||
horizontalScrollerHeight = [CPScroller scrollerWidthForControlSize:[_horizontalScroller controlSize]];
|
||||
verticalScrollerWidth = _CGRectGetWidth([_verticalScroller frame]);
|
||||
horizontalScrollerHeight = _CGRectGetHeight([_horizontalScroller frame]);
|
||||
|
||||
if (_autohidesScrollers)
|
||||
{
|
||||
// Check to see if either affected the other!
|
||||
if (shouldShowVerticalScroller)
|
||||
shouldShowHorizontalScroller = (!_autohidesScrollers || difference.width > -verticalScrollerWidth) && _hasHorizontalScroller;
|
||||
|
||||
if (shouldShowHorizontalScroller)
|
||||
shouldShowVerticalScroller = (!_autohidesScrollers || difference.height > -horizontalScrollerHeight) && _hasVerticalScroller;
|
||||
}
|
||||
|
||||
|
||||
[_verticalScroller setHidden:!shouldShowVerticalScroller];
|
||||
[_verticalScroller setEnabled:!_autohidesScrollers && difference.height < 0];
|
||||
[_verticalScroller setEnabled:difference.height > 0.0];
|
||||
|
||||
[_horizontalScroller setHidden:!shouldShowHorizontalScroller];
|
||||
[_horizontalScroller setEnabled:!_autohidesScrollers && difference.width < 0];
|
||||
[_horizontalScroller setEnabled:difference.width > 0.0];
|
||||
|
||||
if (shouldShowVerticalScroller)
|
||||
{
|
||||
@@ -276,7 +278,7 @@
|
||||
_hasHorizontalScroller = shouldHaveHorizontalScroller;
|
||||
|
||||
if (_hasHorizontalScroller && !_horizontalScroller)
|
||||
[self setHorizontalScroller:[[CPScroller alloc] initWithFrame:CPRectMake(0.0, 0.0, CPRectGetWidth([self bounds]), [CPScroller scrollerWidth])]];
|
||||
[self setHorizontalScroller:[[CPScroller alloc] initWithFrame:CGRectMake(0.0, 0.0, CPRectGetWidth([self bounds]), [CPScroller scrollerWidth])]];
|
||||
|
||||
else if (!_hasHorizontalScroller && _horizontalScroller)
|
||||
{
|
||||
|
||||
+45
-111
@@ -23,7 +23,6 @@
|
||||
@import "CPControl.j"
|
||||
|
||||
#include "CoreGraphics/CGGeometry.h"
|
||||
#include "CPThemedValue.h"
|
||||
|
||||
|
||||
// CPScroller Constants
|
||||
@@ -72,21 +71,29 @@ var PARTS_ARRANGEMENT = [CPScrollerKnobSlot, CPScrollerDecrementLine, CPScroller
|
||||
JSObject _layoutViews;
|
||||
|
||||
CPThemedValue _scrollerWidth;
|
||||
|
||||
CPThemedValue _trackOverlapInset;
|
||||
|
||||
CPArray _horizontalPartColors;
|
||||
CPArray _verticalPartColors;
|
||||
|
||||
CPThemedValue _verticalMinimumKnobSize;
|
||||
CPThemedValue _verticalDecrementLineSize;
|
||||
CPThemedValue _verticalIncrementLineSize;
|
||||
|
||||
CPThemedValue _horizontalMinimumKnobSize;
|
||||
CPThemedValue _horizontalDecrementLineSize;
|
||||
CPThemedValue _horizontalIncrementLineSize;
|
||||
}
|
||||
|
||||
+ (id)themedAttributes
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[ _CGInsetMakeZero(),
|
||||
nil, nil, nil, nil,
|
||||
nil, nil, nil, nil,
|
||||
_CGSizeMakeZero(), _CGSizeMakeZero(), _CGSizeMakeZero(),
|
||||
_CGSizeMakeZero(), _CGSizeMakeZero(), _CGSizeMakeZero()]
|
||||
forKeys:[ @"track-overlap-inset",
|
||||
@"horizontal-" + CPScrollerKnobSlot + "-color",
|
||||
@"horizontal-" + CPScrollerDecrementLine + "-color",
|
||||
@"horizontal-" + CPScrollerIncrementLine + "-color",
|
||||
@"horizontal-" + CPScrollerKnob + "-color",
|
||||
@"vertical-" + CPScrollerKnobSlot + "-color",
|
||||
@"vertical-" + CPScrollerDecrementLine + "-color",
|
||||
@"vertical-" + CPScrollerIncrementLine + "-color",
|
||||
@"vertical-" + CPScrollerKnob + "-color",
|
||||
@"horizontal-decrement-line-size", @"horizontal-increment-line-size", @"horizontal-minimum-knob-size",
|
||||
@"vertical-decrement-line-size", @"vertical-increment-line-size", @"vertical-minimum-knob-size"]];
|
||||
}
|
||||
|
||||
|
||||
// Calculating Layout
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
@@ -101,35 +108,6 @@ var PARTS_ARRANGEMENT = [CPScrollerKnobSlot, CPScrollerDecrementLine, CPScroller
|
||||
[self setFloatValue:0.0 knobProportion:1.0];
|
||||
|
||||
_hitPart = CPScrollerNoPart;
|
||||
|
||||
var theme = [self theme],
|
||||
theClass = [self class];
|
||||
|
||||
_trackOverlapInset = CPThemedValueMake(_CGInsetMakeZero(), "track-overlap-inset", theme, theClass);
|
||||
|
||||
_verticalMinimumKnobSize = CPThemedValueMake(_CGSizeMake(10.0,10.0), "vertical-minimum-knob-size", theme, theClass);
|
||||
_verticalDecrementLineSize = CPThemedValueMake(_CGSizeMakeZero(), "vertical-decrement-line-size", theme, theClass);
|
||||
_verticalIncrementLineSize = CPThemedValueMake(_CGSizeMakeZero(), "vertical-increment-line-size", theme, theClass);
|
||||
|
||||
_horizontalMinimumKnobSize = CPThemedValueMake(_CGSizeMakeZero(), "horizontal-minimum-knob-size", theme, theClass);
|
||||
_horizontalDecrementLineSize = CPThemedValueMake(_CGSizeMakeZero(), "horizontal-decrement-line-size", theme, theClass);
|
||||
_horizontalIncrementLineSize = CPThemedValueMake(_CGSizeMakeZero(), "horizontal-increment-line-size", theme, theClass);
|
||||
|
||||
_horizontalPartColors = [];
|
||||
_verticalPartColors = [];
|
||||
|
||||
var index = 0,
|
||||
count = PARTS_ARRANGEMENT.length;
|
||||
|
||||
for (; index < count; ++index)
|
||||
{
|
||||
var part = PARTS_ARRANGEMENT[index];
|
||||
|
||||
_horizontalPartColors[part] = CPThemedValueMake(nil, "horizontal-" + part + "-color", theme, theClass);
|
||||
_verticalPartColors[part] = CPThemedValueMake(nil, "vertical-" + part + "-color", theme, theClass);
|
||||
}
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -221,50 +199,24 @@ var PARTS_ARRANGEMENT = [CPScrollerKnobSlot, CPScrollerDecrementLine, CPScroller
|
||||
return _knobProportion;
|
||||
}
|
||||
|
||||
THEMED_STATED_VALUE(TrackOverlapInset, trackOverlapInset);
|
||||
|
||||
THEMED_STATED_VALUE(VerticalMinimumKnobSize, verticalMinimumKnobSize);
|
||||
THEMED_STATED_VALUE(VerticalDecrementLineSize, verticalDecrementLineSize);
|
||||
THEMED_STATED_VALUE(VerticalIncrementLineSize, verticalIncrementLineSize);
|
||||
|
||||
THEMED_STATED_VALUE(HorizontalMinimumKnobSize, horizontalMinimumKnobSize);
|
||||
THEMED_STATED_VALUE(HorizontalDecrementLineSize, horizontalDecrementLineSize);
|
||||
THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
|
||||
- (void)setColor:(CPColor)aColor forHorizontalPart:(CPScrollerPart)aScrollerPart controlState:(CPControlState)aControlState
|
||||
- (void)setColor:(CPColor)aColor forHorizontalPart:(CPScrollerPart)aScrollerPart inControlState:(CPControlState)aControlState
|
||||
{
|
||||
var currentValue = [_horizontalPartColors[aScrollerPart] valueForControlState:_controlState];
|
||||
|
||||
[_horizontalPartColors[aScrollerPart] setValue:aColor forControlState:aControlState];
|
||||
|
||||
if ([_horizontalPartColors[aScrollerPart] valueForControlState:_controlState] === currentValue)
|
||||
return;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self setNeedsLayout];
|
||||
[self setValue:aColor forThemedAttributeName:"horizontal-" + aScrollerPart + "-color" inControlState:aControlState];
|
||||
}
|
||||
|
||||
- (CPColor)colorForHorizontalPart:(CPScrollerPart)aScrollerPart controlState:(CPControlState)aControlState
|
||||
- (CPColor)colorForHorizontalPart:(CPScrollerPart)aScrollerPart inControlState:(CPControlState)aControlState
|
||||
{
|
||||
return [_horizontalPartColors[aScrollerPart] valueForControlState:aControlState];
|
||||
return [self valueForThemedAttributeName:"horizontal-" + aScrollerPart + "-color" inControlState:aControlState];
|
||||
}
|
||||
|
||||
- (void)setColor:(CPColor)aColor forHorizontalPart:(CPScrollerPart)aScrollerPart
|
||||
{
|
||||
var currentValue = [_horizontalPartColors[aScrollerPart] valueForControlState:_controlState];
|
||||
|
||||
[_horizontalPartColors[aScrollerPart] setValue:aColor];
|
||||
|
||||
if ([_horizontalPartColors[aScrollerPart] valueForControlState:_controlState] === currentValue)
|
||||
return;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self setNeedsLayout];
|
||||
[self setValue:aColor forThemedAttributeName:"horizontal-" + aScrollerPart + "-color"];
|
||||
}
|
||||
|
||||
- (id)colorForHorizontalPart:(CPScrollerPart)aScrollerPart
|
||||
{
|
||||
return [_horizontalPartColors[aScrollerPart] value];
|
||||
return [self valueForThemedAttributeName:"horizontal-" + aScrollerPart + "-color" inControlState:aControlState];
|
||||
}
|
||||
|
||||
- (id)currentColorForHorizontalPart:(CPScrollerPart)aScrollerPart
|
||||
@@ -274,43 +226,27 @@ THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
if (_hitPart !== aScrollerPart)
|
||||
controlState &= ~CPControlStateHighlighted;
|
||||
|
||||
return [_horizontalPartColors[aScrollerPart] valueForControlState:controlState];
|
||||
return [self valueForThemedAttributeName:"horizontal-" + aScrollerPart + "-color" inControlState:controlState];
|
||||
}
|
||||
|
||||
- (void)setColor:(CPColor)aColor forVerticalPart:(CPScrollerPart)aScrollerPart controlState:(CPControlState)aControlState
|
||||
- (void)setColor:(CPColor)aColor forVerticalPart:(CPScrollerPart)aScrollerPart inControlState:(CPControlState)aControlState
|
||||
{
|
||||
var currentValue = [_verticalPartColors[aScrollerPart] valueForControlState:_controlState];
|
||||
|
||||
[_verticalPartColors[aScrollerPart] setValue:aColor forControlState:aControlState];
|
||||
|
||||
if ([_verticalPartColors[aScrollerPart] valueForControlState:_controlState] === currentValue)
|
||||
return;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self setNeedsLayout];
|
||||
[self setValue:aColor forThemedAttributeName:"vertical-" + aScrollerPart + "-color" inControlState:aControlState];
|
||||
}
|
||||
|
||||
- (CPColor)colorForVerticalPart:(CPScrollerPart)aScrollerPart controlState:(CPControlState)aControlState
|
||||
- (CPColor)colorForVerticalPart:(CPScrollerPart)aScrollerPart inControlState:(CPControlState)aControlState
|
||||
{
|
||||
return [_verticalPartColors[aScrollerPart] valueForControlState:aControlState];
|
||||
return [self valueForThemedAttributeName:"vertical-" + aScrollerPart + "-color" inControlState:aControlState];
|
||||
}
|
||||
|
||||
- (void)setColor:(CPColor)aColor forVerticalPart:(CPScrollerPart)aScrollerPart
|
||||
{
|
||||
var currentValue = [_verticalPartColors[aScrollerPart] valueForControlState:_controlState];
|
||||
|
||||
[_verticalPartColors[aScrollerPart] setValue:aColor];
|
||||
|
||||
if ([_verticalPartColors[aScrollerPart] valueForControlState:_controlState] === currentValue)
|
||||
return;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self setNeedsLayout];
|
||||
[self setValue:aColor forThemedAttributeName:"vertical-" + aScrollerPart + "-color"];
|
||||
}
|
||||
|
||||
- (id)colorForVerticalPart:(CPScrollerPart)aScrollerPart
|
||||
{
|
||||
return [_verticalPartColors[aScrollerPart] value];
|
||||
return [self valueForThemedAttributeName:"vertical-" + aScrollerPart + "-color" inControlState:aControlState];
|
||||
}
|
||||
|
||||
- (id)currentColorForVerticalPart:(CPScrollerPart)aScrollerPart
|
||||
@@ -320,7 +256,7 @@ THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
if (_hitPart !== aScrollerPart)
|
||||
controlState &= ~CPControlStateHighlighted;
|
||||
|
||||
return [_verticalPartColors[aScrollerPart] valueForControlState:controlState];
|
||||
return [self valueForThemedAttributeName:"vertical-" + aScrollerPart + "-color" inControlState:controlState];
|
||||
}
|
||||
|
||||
// Calculating Layout
|
||||
@@ -394,18 +330,18 @@ THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
_usableParts = CPAllScrollerParts;
|
||||
|
||||
var isHorizontal = ![self isVertical],
|
||||
trackOverlapInset = [self currentTrackOverlapInset],
|
||||
trackOverlapInset = [self currentValueForThemedAttributeName:@"track-overlap-inset"],
|
||||
width = _CGRectGetWidth(bounds),
|
||||
height = _CGRectGetHeight(bounds);
|
||||
height = _CGRectGetHeight(bounds);
|
||||
|
||||
if (isHorizontal)
|
||||
{
|
||||
var decrementLineSize = [self currentHorizontalDecrementLineSize],
|
||||
incrementLineSize = [self currentHorizontalIncrementLineSize],
|
||||
var decrementLineSize = [self currentValueForThemedAttributeName:"horizontal-decrement-line-size"],
|
||||
incrementLineSize = [self currentValueForThemedAttributeName:"horizontal-increment-line-size"],
|
||||
effectiveDecrementLineWidth = decrementLineSize.width - trackOverlapInset.left,
|
||||
effectiveIncrementLineWidth = incrementLineSize.width - trackOverlapInset.right;
|
||||
slotWidth = width - effectiveDecrementLineWidth - effectiveIncrementLineWidth,
|
||||
minimumKnobSize = [self currentHorizontalMinimumKnobSize],
|
||||
minimumKnobSize = [self currentValueForThemedAttributeName:"horizontal-minimum-knob-size"],
|
||||
knobWidth = MAX(minimumKnobSize.width, (slotWidth * _knobProportion)),
|
||||
knobLocation = effectiveDecrementLineWidth + (slotWidth - knobWidth) * [self floatValue];
|
||||
|
||||
@@ -418,12 +354,12 @@ THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
var decrementLineSize = [self currentVerticalDecrementLineSize],
|
||||
incrementLineSize = [self currentVerticalIncrementLineSize],
|
||||
var decrementLineSize = [self currentValueForThemedAttributeName:"vertical-decrement-line-size"],
|
||||
incrementLineSize = [self currentValueForThemedAttributeName:"vertical-decrement-line-size"],
|
||||
effectiveDecrementLineHeight = decrementLineSize.height - trackOverlapInset.top,
|
||||
effectiveIncrementLineHeight = incrementLineSize.height - trackOverlapInset.bottom,
|
||||
slotHeight = height - effectiveDecrementLineHeight - effectiveIncrementLineHeight,
|
||||
minimumKnobSize = [self currentVerticalMinimumKnobSize],
|
||||
minimumKnobSize = [self currentValueForThemedAttributeName:"vertical-minimum-knob-size"],
|
||||
knobHeight = MAX(minimumKnobSize.height, (slotHeight * _knobProportion)),
|
||||
knobLocation = effectiveDecrementLineHeight + (slotHeight - knobHeight) * [self floatValue];
|
||||
|
||||
@@ -699,7 +635,7 @@ THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
@implementation CPScroller (Theming)
|
||||
|
||||
- (void)viewDidChangeTheme
|
||||
@@ -767,7 +703,7 @@ THEMED_STATED_VALUE(HorizontalIncrementLineSize, horizontalIncrementLineSize);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
*/
|
||||
var CPScrollerControlSizeKey = "CPScrollerControlSize",
|
||||
CPScrollerKnobProportionKey = "CPScrollerKnobProportion";
|
||||
|
||||
@@ -789,8 +725,6 @@ var CPScrollerControlSizeKey = "CPScrollerControlSize",
|
||||
_verticalPartColors = [];
|
||||
_horizontalPartColors = [];
|
||||
|
||||
_isHorizontal = CPRectGetWidth([self frame]) > CPRectGetHeight([self frame]);
|
||||
|
||||
_hitPart = CPScrollerNoPart;
|
||||
|
||||
// [self checkSpaceForParts];
|
||||
|
||||
+50
-131
@@ -3,7 +3,6 @@
|
||||
@import "CPThemedValue.j"
|
||||
|
||||
#include "CoreGraphics/CGGeometry.h"
|
||||
#include "CPThemedValue.h"
|
||||
|
||||
|
||||
@implementation CPSlider : CPControl
|
||||
@@ -11,17 +10,12 @@
|
||||
double _minValue;
|
||||
double _maxValue;
|
||||
double _altIncrementValue;
|
||||
|
||||
CPThemedValue _verticalTrackColor; // vertical-track-color
|
||||
CPThemedValue _horizontalTrackColor; // horizontal-track-color
|
||||
|
||||
CPThemedValue _knobColor;
|
||||
|
||||
CPThemedValue _trackWidth; // track-width
|
||||
CPThemedValue _knobSize; // knob-size
|
||||
|
||||
CPView _trackView;
|
||||
CPView _knobView;
|
||||
}
|
||||
|
||||
+ (id)themedAttributes
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[nil, _CGSizeMakeZero(), 0.0, nil, nil]
|
||||
forKeys:[@"knob-color", @"knob-size", @"track-width", @"vertical-track-color", @"horizontal-track-color"]];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
@@ -33,16 +27,6 @@
|
||||
_minValue = 0.0;
|
||||
_maxValue = 100.0;
|
||||
|
||||
var theme = [self theme],
|
||||
theClass = [self class];
|
||||
|
||||
_knobColor = CPThemedValueMake(nil, "knob-color", theme, theClass);
|
||||
_knobSize = CPThemedValueMake(_CGSizeMakeZero(), "knob-size", theme, theClass);
|
||||
|
||||
_trackWidth = CPThemedValueMake(0.0, "track-width", theme, theClass);
|
||||
_verticalTrackColor = CPThemedValueMake(nil, "vertical-track-color", theme, theClass);
|
||||
_horizontalTrackColor = CPThemedValueMake(nil, "horizonal-track-color", theme, theClass);
|
||||
|
||||
[self setObjectValue:50.0];
|
||||
|
||||
[self setContinuous:YES];
|
||||
@@ -97,7 +81,7 @@
|
||||
|
||||
- (CGRect)trackRectForBounds:(CGRect)bounds
|
||||
{
|
||||
var trackWidth = [self currentTrackWidth];
|
||||
var trackWidth = [self currentValueForThemedAttributeName:@"track-width"];
|
||||
|
||||
if (trackWidth <= 0)
|
||||
return _CGRectMakeZero();
|
||||
@@ -116,15 +100,9 @@
|
||||
return bounds;
|
||||
}
|
||||
|
||||
THEMED_STATED_VALUE(KnobColor, knobColor)
|
||||
THEMED_STATED_VALUE(KnobSize, knobSize)
|
||||
THEMED_STATED_VALUE(TrackWidth, trackWidth)
|
||||
THEMED_STATED_VALUE(HorizontalTrackColor, horizontalTrackColor)
|
||||
THEMED_STATED_VALUE(VerticalTrackColor, verticalTrackColor)
|
||||
|
||||
- (CGRect)knobRectForBounds:(CGRect)bounds
|
||||
{
|
||||
var knobSize = [self currentKnobSize];
|
||||
var knobSize = [self currentValueForThemedAttributeName:@"knob-size"];
|
||||
|
||||
if (knobSize.width <= 0 || knobSize.height <= 0)
|
||||
return _CGRectMakeZero();
|
||||
@@ -150,6 +128,31 @@ THEMED_STATED_VALUE(VerticalTrackColor, verticalTrackColor)
|
||||
return knobRect;
|
||||
}
|
||||
|
||||
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
|
||||
{
|
||||
if (aName === "track-view")
|
||||
return [self trackRectForBounds:[self bounds]];
|
||||
|
||||
else if (aName === "knob-view")
|
||||
return [self knobRectForBounds:[self bounds]];
|
||||
|
||||
return [super rectForEphemeralSubviewNamed:aName];
|
||||
}
|
||||
|
||||
- (CPView)createEphemeralSubviewNamed:(CPString)aName
|
||||
{
|
||||
if (aName === "track-view" || aName === "knob-view")
|
||||
{
|
||||
var view = [[CPView alloc] init];
|
||||
|
||||
[view setHitTests:NO];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
return [super createEphemeralSubviewNamed:aName];
|
||||
}
|
||||
|
||||
- (int)isVertical
|
||||
{
|
||||
var bounds = [self bounds],
|
||||
@@ -159,91 +162,24 @@ THEMED_STATED_VALUE(VerticalTrackColor, verticalTrackColor)
|
||||
return width < height ? 1 : (width > height ? 0 : -1);
|
||||
}
|
||||
|
||||
- (CPView)createTrackView
|
||||
{
|
||||
var trackView = [[CPView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
|
||||
[trackView setHitTests:NO];
|
||||
|
||||
return trackView;
|
||||
}
|
||||
|
||||
- (CPView)createKnobView
|
||||
{
|
||||
var knobView = [[CPView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
|
||||
[knobView setHitTests:NO];
|
||||
|
||||
return knobView;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
var bounds = [self bounds],
|
||||
isVertical = [self isVertical],
|
||||
trackRect = nil;
|
||||
var trackView = [self layoutEphemeralSubviewNamed:@"track-view"
|
||||
positioned:CPWindowBelow
|
||||
relativeToEphemeralSubviewNamed:@"knob-view"];
|
||||
|
||||
if (trackView)
|
||||
if ([self isVertical])
|
||||
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"vertical-track-color"]];
|
||||
else
|
||||
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"horizontal-track-color"]];
|
||||
|
||||
if ((trackRect = [self trackRectForBounds:_CGRectMakeCopy(bounds)]) && !_CGRectIsEmpty(trackRect))
|
||||
{
|
||||
if (!_trackView)
|
||||
{
|
||||
_trackView = [self createTrackView];
|
||||
|
||||
if (_trackView)
|
||||
[self addSubview:_trackView positioned:CPWindowBelow relativeTo:_knobView];
|
||||
}
|
||||
|
||||
if (_trackView)
|
||||
{
|
||||
[_trackView setFrame:trackRect];
|
||||
|
||||
if ([self isVertical])
|
||||
{
|
||||
if (_verticalTrackColor)
|
||||
[_trackView setBackgroundColor:[self currentVerticalTrackColor]];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_horizontalTrackColor)
|
||||
[_trackView setBackgroundColor:[self currentHorizontalTrackColor]];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_trackView)
|
||||
{
|
||||
[_trackView removeFromSuperview];
|
||||
|
||||
_trackView = nil;
|
||||
}
|
||||
|
||||
var knobRect = nil;
|
||||
|
||||
if ((knobRect = [self knobRectForBounds:bounds]) && !_CGRectIsEmpty(knobRect))
|
||||
{
|
||||
if (!_knobView)
|
||||
{
|
||||
_knobView = [self createKnobView];
|
||||
|
||||
if (_knobView)
|
||||
[self addSubview:_knobView positioned:CPWindowAbove relativeTo:_trackView];
|
||||
}
|
||||
|
||||
if (_knobView)
|
||||
{
|
||||
[_knobView setFrame:knobRect];
|
||||
|
||||
var knobColor = [self currentKnobColor];
|
||||
|
||||
if (knobColor)
|
||||
[_knobView setBackgroundColor:knobColor];
|
||||
}
|
||||
}
|
||||
else if (_knobView)
|
||||
{
|
||||
[_knobView removeFromSuperview];
|
||||
|
||||
_knobView = nil;
|
||||
}
|
||||
var knobView = [self layoutEphemeralSubviewNamed:@"knob-view"
|
||||
positioned:CPWindowAbove
|
||||
relativeToEphemeralSubviewNamed:@"track-view"];
|
||||
|
||||
if (knobView)
|
||||
[knobView setBackgroundColor:[self currentValueForThemedAttributeName:"knob-color"]];
|
||||
}
|
||||
|
||||
- (BOOL)tracksMouseOutsideOfFrame
|
||||
@@ -342,7 +278,7 @@ THEMED_STATED_VALUE(VerticalTrackColor, verticalTrackColor)
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
@implementation CPSlider (Theming)
|
||||
|
||||
- (void)viewDidChangeTheme
|
||||
@@ -382,7 +318,7 @@ THEMED_STATED_VALUE(VerticalTrackColor, verticalTrackColor)
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
*/
|
||||
var CPSliderMinValueKey = "CPSliderMinValueKey",
|
||||
CPSliderMaxValueKey = "CPSliderMaxValueKey",
|
||||
CPSliderAltIncrValueKey = "CPSliderAltIncrValueKey",
|
||||
@@ -404,17 +340,7 @@ var CPSliderMinValueKey = "CPSliderMinValueKey",
|
||||
_minValue = [aCoder decodeDoubleForKey:CPSliderMinValueKey];
|
||||
_maxValue = [aCoder decodeDoubleForKey:CPSliderMaxValueKey];
|
||||
_altIncrementValue = [aCoder decodeDoubleForKey:CPSliderAltIncrValueKey];
|
||||
|
||||
var theme = [self theme],
|
||||
theClass = [self class];
|
||||
|
||||
_knobColor = CPThemedValueDecode(aCoder, CPSliderKnobColorKey, nil, "knob-color", theme, theClass);
|
||||
_knobSize = CPThemedValueDecode(aCoder, CPSliderKnobSizeKey, nil, "knob-size", theme, theClass);
|
||||
|
||||
_trackWidth = CPThemedValueDecode(aCoder, CPSliderKnobColorKey, nil, "track-width", theme, theClass);
|
||||
_horizontalTrackColor = CPThemedValueDecode(aCoder, CPSliderHorizontalTrackColorKey, nil, "horizontal-track-color", theme, theClass);
|
||||
_verticalTrackColor = CPThemedValueDecode(aCoder, CPSliderVerticalTrackColorKey, nil, "vertical-track-color", theme, theClass);
|
||||
|
||||
[self setContinuous:YES];
|
||||
|
||||
[self setNeedsLayout];
|
||||
@@ -453,13 +379,6 @@ var CPSliderMinValueKey = "CPSliderMinValueKey",
|
||||
[aCoder encodeDouble:_minValue forKey:CPSliderMinValueKey];
|
||||
[aCoder encodeDouble:_maxValue forKey:CPSliderMaxValueKey];
|
||||
[aCoder encodeDouble:_altIncrementValue forKey:CPSliderAltIncrValueKey];
|
||||
|
||||
CPThemedValueEncode(aCoder, CPSliderKnobColorKey, _knobColor);
|
||||
CPThemedValueEncode(aCoder, CPSliderKnobSizeKey, _knobSize);
|
||||
|
||||
CPThemedValueEncode(aCoder, CPSliderTrackWidthKey, _trackWidth);
|
||||
CPThemedValueEncode(aCoder, CPSliderHorizontalTrackColorKey, _horizontalTrackColor);
|
||||
CPThemedValueEncode(aCoder, CPSliderVerticalTrackColorKey, _verticalTrackColor);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+140
-6
@@ -88,7 +88,8 @@ CPViewFrameDidChangeNotification = @"CPViewFrameDidChangeNotification";
|
||||
var _DOMOriginUpdateMask = 1 << 0,
|
||||
_DOMSizeUpdateMask = 1 << 1;
|
||||
|
||||
var _CPViewNotificationCenter = nil;
|
||||
var _CPViewNotificationCenter = nil,
|
||||
_CachedThemedAttributes = nil;
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
var DOMElementPrototype = nil,
|
||||
@@ -155,7 +156,6 @@ var DOMElementPrototype = nil,
|
||||
#endif
|
||||
|
||||
CGRect _dirtyRect;
|
||||
BOOL _needsLayout;
|
||||
|
||||
float _opacity;
|
||||
CPColor _backgroundColor;
|
||||
@@ -171,8 +171,13 @@ var DOMElementPrototype = nil,
|
||||
|
||||
_CPViewFullScreenModeState _fullScreenModeState;
|
||||
|
||||
// Layout Support
|
||||
BOOL _needsLayout;
|
||||
JSObject _ephemeralSubviews;
|
||||
|
||||
// Theming Support
|
||||
CPTheme _theme;
|
||||
JSObject _themedAttributes;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -245,6 +250,9 @@ var DOMElementPrototype = nil,
|
||||
#endif
|
||||
|
||||
_theme = [CPTheme defaultTheme];
|
||||
_themedAttributes = {};
|
||||
|
||||
[self _loadThemedAttributes];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -1780,16 +1788,77 @@ setBoundsOrigin:
|
||||
|
||||
@implementation CPView (Theming)
|
||||
|
||||
+ (CPDictionary)themedAttributes
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (CPArray)_themedAttributes
|
||||
{
|
||||
if (!_CachedThemedAttributes)
|
||||
_CachedThemedAttributes = {};
|
||||
|
||||
var theClass = [self class],
|
||||
CPViewClass = [CPView class],
|
||||
attributes = [];
|
||||
|
||||
while (theClass && theClass !== CPViewClass)
|
||||
{
|
||||
var cachedAttributes = _CachedThemedAttributes[class_getName(theClass)];
|
||||
|
||||
if (cachedAttributes)
|
||||
{
|
||||
attributes = attributes.length ? attributes.concat(cachedAttributes) : attributes;
|
||||
_CachedThemedAttributes[[self className]] = attributes;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var attributeDictionary = [theClass themedAttributes];
|
||||
|
||||
if (attributeDictionary)
|
||||
{
|
||||
var attributeKeys = [attributeDictionary allKeys],
|
||||
attributeCount = attributeKeys.length;
|
||||
|
||||
while (attributeCount--)
|
||||
{
|
||||
var attributeName = attributeKeys[attributeCount];
|
||||
|
||||
attributes.push([attributeDictionary objectForKey:attributeName]);
|
||||
attributes.push(attributeName);
|
||||
}
|
||||
}
|
||||
|
||||
theClass = [theClass superclass];
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
- (void)_loadThemedAttributes
|
||||
{
|
||||
var theme = [self theme],
|
||||
theClass = [self class],
|
||||
attributes = [theClass _themedAttributes];
|
||||
count = attributes.length;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
var attributeName = attributes[count--];
|
||||
|
||||
_themedAttributes[attributeName] = CPThemedValueMake(attributes[count], attributeName, theme, theClass);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTheme:(CPTheme)aTheme
|
||||
{
|
||||
if (_theme === aTheme)
|
||||
return;
|
||||
|
||||
_theme = aTheme;
|
||||
|
||||
[_theme setActiveClass:[self class]];
|
||||
|
||||
[self viewDidChangeTheme];
|
||||
[_theme setActiveClass:Nil];
|
||||
}
|
||||
|
||||
- (CPTheme)theme
|
||||
@@ -1799,11 +1868,60 @@ setBoundsOrigin:
|
||||
|
||||
- (void)viewDidChangeTheme
|
||||
{
|
||||
var theme = [self theme];
|
||||
|
||||
for (var attributeName in _themedAttributes)
|
||||
if (_themedAttributes.hasOwnProperty(attributeName))
|
||||
[_themedAttributes[attributeName] setTheme:theme];
|
||||
}
|
||||
|
||||
- (CPDictionary)themedValues
|
||||
{
|
||||
return [CPDictionary dictionary];
|
||||
var dictionary = [CPDictionary dictionary];
|
||||
|
||||
for (var attributeName in _themedAttributes)
|
||||
if (_themedAttributes.hasOwnProperty(attributeName))
|
||||
[dictionary setObject:_themedAttributes[attributeName] forKey:attributeName];
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
- (void)setValue:(id)aValue forThemedAttributeName:(CPString)aName inControlState:(CPControlState)aControlState
|
||||
{
|
||||
var attribute = _themedAttributes[aName];
|
||||
|
||||
if (!attribute)
|
||||
return nil;
|
||||
|
||||
var currentValue = [self currentValueForThemedAttributeName:aName];
|
||||
|
||||
[attribute setValue:aValue forControlState:aControlState];
|
||||
|
||||
if ([self currentValueForThemedAttributeName:aName] === currentValue)
|
||||
return;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setValue:(id)aValue forThemedAttributeName:(CPString)aName
|
||||
{
|
||||
[_themedAttributes[aName] setValue:aValue];
|
||||
}
|
||||
|
||||
- (id)valueForThemedAttributeName:(CPString)aName inControlState:(CPControlState)aControlState
|
||||
{
|
||||
return [_themedAttributes[aName] valueForControlState:aControlState];
|
||||
}
|
||||
|
||||
- (id)valueForThemedAttributeName:(CPString)aName
|
||||
{
|
||||
return [_themedAttributes[aName] value];
|
||||
}
|
||||
|
||||
- (void)currentValueForThemedAttributeName:(CPString)aName
|
||||
{
|
||||
return [_themedAttributes[aName] valueForControlState:_controlState];//[self controlStateForThemedAttributeName:aName]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1884,6 +2002,18 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
|
||||
[self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]];
|
||||
|
||||
_theme = [CPTheme defaultTheme];
|
||||
_themedAttributes = {};
|
||||
|
||||
var theClass = [self class],
|
||||
attributes = [theClass _themedAttributes],
|
||||
count = attributes.length;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
var attributeName = attributes[count--];
|
||||
|
||||
_themedAttributes[attributeName] = CPThemedValueDecode2(aCoder, attributeName, attributes[count], _theme, theClass);
|
||||
}
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
@@ -1917,6 +2047,10 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
|
||||
[aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
|
||||
[aCoder encodeBool:_isHidden forKey:CPViewIsHiddenKey];
|
||||
[aCoder encodeFloat:_opacity forKey:CPViewOpacityKey];
|
||||
|
||||
for (var attributeName in _themedAttributes)
|
||||
if (_themedAttributes.hasOwnProperty(attributeName))
|
||||
CPThemedValueEncode2(aCoder, _themedAttributes[attributeName]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in new issue
Block a user