Huge audit of ITKit, mostly everything has been updated to current coding
[ITKit.git] / ITTextFieldCell.m
1 #import "ITTextFieldCell.h"
2 #import "ITCoreGraphicsHacks.h"
3 #import <ApplicationServices/ApplicationServices.h>
4
5 @implementation ITTextFieldCell
6
7 - (id)initTextCell:(NSString *)string {
8         if ((self = [super initTextCell:string])) {
9                 castsShadow = NO;
10                 shadowElevation = 45.0;
11                 shadowAzimuth = 90.0;
12                 shadowAmbient = 0.15;
13                 shadowHeight = 1.00;
14                 shadowRadius = 4.00;
15                 shadowSaturation = 1.0;
16         }
17         return self;
18 }
19
20 - (id)initWithCoder:(NSCoder *)coder {
21         if ((self = [super initWithCoder:coder])) {             
22                 castsShadow = NO;
23                 shadowElevation = 45.0;
24                 shadowAzimuth = 90.0;
25                 shadowAmbient = 0.15;
26                 shadowHeight = 1.00;
27                 shadowRadius = 4.00;
28                 shadowSaturation = 1.0;
29         }
30         return self;
31 }
32
33 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView {
34         CGSGenericObj style = nil;
35         CGShadowStyle shadow;
36         
37         if ( castsShadow ) { 
38                 // Create the shadow style to use for drawing the string
39                 shadow.version = 0;
40                 shadow.elevation = shadowElevation;
41                 shadow.azimuth = shadowAzimuth;
42                 shadow.ambient = shadowAmbient;
43                 shadow.height = shadowHeight;
44                 shadow.radius = shadowRadius;
45                 shadow.saturation = shadowSaturation;
46                 style = CGStyleCreateShadow(&shadow);
47                 
48                 // Set the context for drawing the string
49                 [NSGraphicsContext saveGraphicsState];
50                 CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
51         }
52         
53         // Draw the string
54         [super drawWithFrame:rect inView:controlView];
55         
56         if (castsShadow) { 
57                 // Restore the old context
58                 [NSGraphicsContext restoreGraphicsState];
59                 CGStyleRelease(style);
60         }
61 }
62
63 - (BOOL)castsShadow {
64         return castsShadow;
65 }
66
67 - (void)setCastsShadow:(BOOL)newSetting {
68         castsShadow = newSetting;
69         [[self controlView] setNeedsDisplay:YES];
70 }
71
72 - (float)shadowElevation {
73         return shadowElevation;
74 }
75
76 - (void)setShadowElevation:(float)newElevation {
77         shadowElevation = newElevation;
78         [[self controlView] setNeedsDisplay:YES];
79 }
80
81 - (float)shadowAzimuth {
82         return shadowAzimuth;
83 }
84
85 - (void)setShadowAzimuth:(float)newAzimuth {
86         shadowAzimuth = newAzimuth;
87         [[self controlView] setNeedsDisplay:YES];
88 }
89
90 - (float)shadowAmbient {
91         return shadowAmbient;
92 }
93
94 - (void)setShadowAmbient:(float)newAmbient {
95         shadowAmbient = newAmbient;
96         [[self controlView] setNeedsDisplay:YES];
97 }
98
99 - (float)shadowHeight {
100         return shadowHeight;
101 }
102
103 - (void)setShadowHeight:(float)newHeight {
104         shadowHeight = newHeight;
105         [[self controlView] setNeedsDisplay:YES];
106 }
107
108 - (float)shadowRadius {
109         return shadowRadius;
110 }
111
112 - (void)setShadowRadius:(float)newRadius {
113         shadowRadius = newRadius;
114         [[self controlView] setNeedsDisplay:YES];
115 }
116
117 - (float)shadowSaturation {
118         return shadowSaturation;
119 }
120
121 - (void)setShadowSaturation:(float)newSaturation {
122         shadowSaturation = newSaturation;
123         [[self controlView] setNeedsDisplay:YES];
124 }
125
126 @end