Skip to content

Commit

Permalink
Added support for cross-browser text shadows in _CPImageAndTextView.
Browse files Browse the repository at this point in the history
Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed Jan 27, 2009
1 parent 9e7fd7f commit 10b3496
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 102 deletions.
40 changes: 7 additions & 33 deletions AppKit/CPButton.j
Expand Up @@ -326,19 +326,15 @@ var _CPButtonClassName = nil,

if (self)
{


[self setAlignment:CPCenterTextAlignment];
[self setVerticalAlignment:CPCenterVerticalTextAlignment];

_imagePosition = CPImageLeft;
_imageScaling = CPScaleNone;
[self setImagePosition:CPImageLeft];
[self setImageScaling:CPScaleNone];

_controlSize = CPRegularControlSize;

[self setBezelStyle:CPRoundRectBezelStyle];
[self setBordered:YES];

[self setAlignment:CPCenterTextAlignment];
}

return self;
Expand All @@ -350,20 +346,9 @@ var _CPButtonClassName = nil,
*/
- (void)setImagePosition:(CPCellImagePosition)anImagePosition
{
if (_imagePosition == anImagePosition)
return;

_imagePosition = anImagePosition;
[super setImagePosition:anImagePosition];

[_imageAndTextView setImagePosition:_imagePosition];
}

/*!
Returns the buton's image position
*/
- (CPCellImagePosition)imagePosition
{
return _imagePosition;
[_imageAndTextView setImagePosition:[self imagePosition]];
}

/*!
Expand All @@ -372,20 +357,9 @@ var _CPButtonClassName = nil,
*/
- (void)setImageScaling:(CPImageScaling)anImageScaling
{
if (_imageScaling == anImageScaling)
return;

_imageScaling = anImageScaling;

[_imageAndTextView setImageScaling:anImageScaling];
}
[super setImageScaling:anImageScaling];

/*!
Returns the button's image scaling method
*/
- (CPImageScaling)imageScaling
{
return _imageScaling;
[_imageAndTextView setImageScaling:[self imageScaling]];
}

/*!
Expand Down
144 changes: 102 additions & 42 deletions AppKit/CPControl.j
Expand Up @@ -86,29 +86,36 @@ var CPControlBlackColor = [CPColor blackColor];
*/
@implementation CPControl : CPView
{
id _value;

BOOL _isEnabled;
id _value;
BOOL _isEnabled;

int _alignment;
// Display Properties
CPTextAlignment _alignment;
CPVerticalTextAlignment _verticalAlignment;
CPFont _font;
CPColor _textColor;
CPShadow _textShadow;

CPLineBreakMode _lineBreakMode;
CPLineBreakMode _lineBreakMode;
CPColor _textColor;
CPFont _font;

CPCellImagePosition _imagePosition;
CPImageScaling _imageScaling;

id _target;
SEL _action;
int _sendActionOn;
// Target-Action Support
id _target;
SEL _action;
int _sendActionOn;

// Mouse Tracking Support
BOOL _continuousTracking;
BOOL _trackingWasWithinFrame;
unsigned _trackingMouseDownFlags;
CGPoint _previousTrackingLocation;

// Stuff
CPShadow _textShadow;

CPDictionary _backgroundColors;
CPString _currentBackgroundColorName;

BOOL _continuousTracking;
BOOL _trackingWasWithinFrame;
unsigned _trackingMouseDownFlags;
CGPoint _previousTrackingLocation;
}

- (id)initWithFrame:(CGRect)aFrame
Expand Down Expand Up @@ -150,32 +157,8 @@ var CPControlBlackColor = [CPColor blackColor];
return _isEnabled;
}


/*!
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 alignment
Sets the receiver's horizontal text alignment
@param anAlignment the receiver's alignment
*/
- (void)setAlignment:(CPTextAlignment)anAlignment
Expand All @@ -184,33 +167,70 @@ var CPControlBlackColor = [CPColor blackColor];
}

/*!
Returns the receiver's alignment
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
Expand All @@ -235,6 +255,46 @@ var CPControlBlackColor = [CPColor blackColor];
return _font;
}

/*!
Sets the position of the button's image to <code>anImagePosition</code>.
@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
Expand Down
18 changes: 15 additions & 3 deletions AppKit/CPMenuItem.j
Expand Up @@ -1009,6 +1009,7 @@ var _CPMenuItemSelectionColor = nil,
_imageAndTextView = [[_CPImageAndTextView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 0.0)];

[_imageAndTextView setImagePosition:CPImageLeft];
[_imageAndTextView setTextShadowOffset:CGSizeMake(0.0, 1.0)];

[self addSubview:_imageAndTextView];
}
Expand All @@ -1029,6 +1030,9 @@ var _CPMenuItemSelectionColor = nil,

var frame = [_imageAndTextView frame];

frame.size.height += 1.0;
[_imageAndTextView setFrame:frame];

frame.size.height += 2 * VERTICAL_MARGIN;

x += CGRectGetWidth(frame);
Expand Down Expand Up @@ -1084,14 +1088,22 @@ var _CPMenuItemSelectionColor = nil,
if (_belongsToMenuBar)
[_imageAndTextView setImage:shouldHighlight ? [_menuItem alternateImage] : [_menuItem image]];

else if([_menuItem isEnabled])
else if ([_menuItem isEnabled])
{
[_imageAndTextView setTextColor:shouldHighlight ? [CPColor whiteColor] : [self textColor]];

if (shouldHighlight)
{
[self setBackgroundColor:_CPMenuItemSelectionColor];

[_imageAndTextView setTextColor:[CPColor whiteColor]];
[_imageAndTextView setTextShadowColor:[CPColor blackColor]];
}
else
{
[self setBackgroundColor:nil];

[_imageAndTextView setTextColor:[self textColor]];
[_imageAndTextView setTextShadowColor:nil];
}

var state = [_menuItem state];

Expand Down

0 comments on commit 10b3496

Please sign in to comment.