w00t. ITButton and ITButtonCell. Also, ITTextField is now correctly implemented...
[ITKit.git] / ITTextField.m
index 3ab85b7..7c0c92b 100755 (executable)
@@ -1,4 +1,5 @@
 #import "ITTextField.h"
+#import "ITTextFieldCell.h"
 #import <CoreGraphics/CoreGraphics.h>
 #import "ITCoreGraphicsHacks.h"
 
 
 @implementation ITTextField
 
+
 /*************************************************************************/
 #pragma mark -
 #pragma mark INITIALIZATION METHODS
 /*************************************************************************/
 
-- (id)initWithFrame:(NSRect)frameRect
++ (void)initialize
 {
-    if ( ( self = [super initWithFrame:frameRect] ) ) {
-        castsShadow      = NO;
-        shadowElevation  = 45.0;
-        shadowAzimuth    = 90.0;
-        shadowAmbient    = 0.15;
-        shadowHeight     = 1.00;
-        shadowRadius     = 4.00;
-        shadowSaturation = 1.0;
+    if ( self == [ITTextField class] ) {
+        [self setCellClass:[ITTextFieldCell class]];
     }
-
-    return self;
 }
 
-- (id)initWithCoder:(NSCoder *)coder
++ (Class)cellClass
 {
-    if ( ( self = [super initWithCoder:coder] ) ) {
-        castsShadow      = NO;
-        shadowElevation  = 45.0;
-        shadowAzimuth    = 90.0;
-        shadowAmbient    = 0.15;
-        shadowHeight     = 1.00;
-        shadowRadius     = 4.00;
-        shadowSaturation = 1.0;
-    }
-    
-    return self;
+    return [ITTextFieldCell class];
 }
 
 
-/*************************************************************************/
-#pragma mark -
-#pragma mark DRAWING METHODS
-/*************************************************************************/
-
-- (void)drawRect:(NSRect)rect
-{
-    CGSGenericObj        style = nil;
-    CGShadowStyle        shadow;
-
-    if ( castsShadow ) { 
-        // Create the shadow style to use for drawing the string
-        shadow.version    = 0;
-        shadow.elevation  = shadowElevation;
-        shadow.azimuth    = shadowAzimuth;
-        shadow.ambient    = shadowAmbient;
-        shadow.height     = shadowHeight;
-        shadow.radius     = shadowRadius;
-        shadow.saturation = shadowSaturation;
-        style = CGStyleCreateShadow(&shadow);
-        
-        // Set the context for drawing the string
-        [NSGraphicsContext saveGraphicsState];
-        CGContextSetStyle([[NSGraphicsContext currentContext] graphicsPort], style);
-    }
-    
-    // Draw the string
-    [super drawRect:rect];
-    
-
-    if ( castsShadow ) { 
-        // Restore the old context
-        [NSGraphicsContext restoreGraphicsState];
-        CGStyleRelease(style);
-    }
-}
-
-
-
 /*************************************************************************/
 #pragma mark -
 #pragma mark ACCESSOR METHODS
 
 - (BOOL)castsShadow;
 {
-    return castsShadow;
+    return [[self cell] castsShadow];
 }
 
 - (void)setCastsShadow:(BOOL)newSetting;
 {
-    castsShadow = newSetting;
-    [self setNeedsDisplay:YES];
+    [[self cell] setCastsShadow:newSetting];
 }
 
 - (float)shadowElevation;
 {
-    return shadowElevation;
+    return [[self cell] shadowElevation];
 }
 
 - (void)setShadowElevation:(float)newElevation;
 {
-    shadowElevation = newElevation;
-    [self setNeedsDisplay:YES];
+    [[self cell] setShadowElevation:newElevation];
 }
 
 - (float)shadowAzimuth;
 {
-    return shadowAzimuth;
+    return [[self cell] shadowAzimuth];
 }
 
 - (void)setShadowAzimuth:(float)newAzimuth;
 {
-    shadowAzimuth = newAzimuth;
-    [self setNeedsDisplay:YES];
+    [[self cell] setShadowAzimuth:newAzimuth];
 }
 
 - (float)shadowAmbient;
 {
-    return shadowAmbient;
+    return [[self cell] shadowAmbient];
 }
 
 - (void)setShadowAmbient:(float)newAmbient;
 {
-    shadowAmbient = newAmbient;
-    [self setNeedsDisplay:YES];
+    [[self cell] setShadowAmbient:newAmbient];
 }
 
 - (float)shadowHeight;
 {
-    return shadowHeight;
+    return [[self cell] shadowHeight];
 }
 
 - (void)setShadowHeight:(float)newHeight;
 {
-    shadowHeight = newHeight;
-    [self setNeedsDisplay:YES];
+    [[self cell] setShadowHeight:newHeight];
 }
 
 - (float)shadowRadius;
 {
-    return shadowRadius;
+    return [[self cell] shadowRadius];
 }
 
 - (void)setShadowRadius:(float)newRadius;
 {
-    shadowRadius = newRadius;
-    [self setNeedsDisplay:YES];
+    [[self cell] setShadowRadius:newRadius];
 }
 
 - (float)shadowSaturation;
 {
-    return shadowSaturation;
+    return [[self cell] shadowSaturation];
 }
 
 - (void)setShadowSaturation:(float)newSaturation;
 {
-    shadowSaturation = newSaturation;
-    [self setNeedsDisplay:YES];
+    [[self cell] setShadowSaturation:newSaturation];
 }