1 #import "ITTextFieldCell.h"
2 #import <ApplicationServices/ApplicationServices.h>
3 #import <ITFoundation/ITFoundation.h>
5 @implementation ITTextFieldCell
7 - (id)initTextCell:(NSString *)string {
8 if ((self = [super initTextCell:string])) {
18 - (id)initWithCoder:(NSCoder *)coder {
19 if ((self = [super initWithCoder:coder])) {
22 shadowAmbient = 0.0; // Unlike ITImageCell, even an alpha component of 1.0 is ligher than the old private API's results. There's not much we can do about it as we can't go "blacker" than black.
29 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView {
33 CGFloat height = ((2.0*tan((M_PI/360.0)*(shadowAzimuth-180.0)))*shadowHeight)/(1.0+pow(tan((M_PI/360.0)*(shadowAzimuth-180.0)),2.0));
34 CGFloat width = sqrt(pow(shadowHeight, 2.0)-pow(height, 2.0));
36 shadow = [[NSShadow alloc] init];
37 [shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:(1.0 - shadowAmbient)]];
38 [shadow setShadowOffset:NSMakeSize(width, height)];
39 [shadow setShadowBlurRadius:shadowRadius];
41 [NSGraphicsContext saveGraphicsState];
46 [super drawWithFrame:rect inView:controlView];
49 // Restore the old context
50 [NSGraphicsContext restoreGraphicsState];
59 - (void)setCastsShadow:(BOOL)newSetting {
60 castsShadow = newSetting;
61 [[self controlView] setNeedsDisplay:YES];
64 - (float)shadowElevation {
68 - (void)setShadowElevation:(float)newElevation {
69 ITDebugLog(@"setShadowElevation: on ITTextFieldCell objects does nothing.");
72 - (float)shadowAzimuth {
76 - (void)setShadowAzimuth:(float)newAzimuth {
77 shadowAzimuth = newAzimuth;
78 [[self controlView] setNeedsDisplay:YES];
81 - (float)shadowAmbient {
85 - (void)setShadowAmbient:(float)newAmbient {
86 shadowAmbient = newAmbient;
87 [[self controlView] setNeedsDisplay:YES];
90 - (float)shadowHeight {
94 - (void)setShadowHeight:(float)newHeight {
95 shadowHeight = newHeight;
96 [[self controlView] setNeedsDisplay:YES];
99 - (float)shadowRadius {
103 - (void)setShadowRadius:(float)newRadius {
104 shadowRadius = newRadius;
105 [[self controlView] setNeedsDisplay:YES];
108 - (float)shadowSaturation {
112 - (void)setShadowSaturation:(float)newSaturation {
113 ITDebugLog(@"setShadowSaturation: on ITTextFieldCell objects does nothing.");