Added category on NSMenu which supports indenting items (uses Carbon in
[ITKit.git] / ITButtonCell.m
1 #import "ITButtonCell.h"
2 #import "ITTextFieldCell.h"
3
4
5 #define GRAY_EXTRA_PAD_H 60.0
6
7
8 @interface ITButtonCell (Private)
9 - (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView;
10 @end
11
12
13 @implementation ITButtonCell
14
15 - (id)init
16 {
17     if ( ( self = [super init] ) ) {
18         _subStyle = 0;
19     }
20     
21     return self;
22 }
23
24
25
26 /*************************************************************************/
27 #pragma mark -
28 #pragma mark INSTANCE METHODS
29 /*************************************************************************/
30
31 - (void)setBezelStyle:(NSBezelStyle)bezelStyle
32 {
33     if ( bezelStyle == ITGrayRoundedBezelStyle ) {
34         _subStyle  = bezelStyle;
35         bezelStyle = NSRegularSquareBezelStyle;
36     } else {
37         _subStyle = 0;
38     }
39
40     [super setBezelStyle:bezelStyle];
41 }
42
43
44 /*************************************************************************/
45 #pragma mark -
46 #pragma mark DRAWING METHODS
47 /*************************************************************************/
48
49 - (void)drawWithFrame:(NSRect)rect inView:(NSView *)controlView
50 {
51     if ( _subStyle == ITGrayRoundedBezelStyle ) {
52         [self drawGrayRoundedBezelWithFrame:rect inView:controlView];
53         [super drawInteriorWithFrame:rect inView:controlView];
54     } else {
55         [super drawWithFrame:rect inView:controlView];
56     }
57 }
58
59 - (void)drawGrayRoundedBezelWithFrame:(NSRect)rect inView:(NSView *)controlView
60 {
61     NSBezierPath *path   = [NSBezierPath bezierPath];
62     float         ch     = rect.size.height;
63     float         cw     = rect.size.width;
64     float         radius = ( ch / 2 );
65     NSPoint       pointA = NSMakePoint( (ch / 2)        , 0.0      );
66     NSPoint       pointB = NSMakePoint( (cw - (ch / 2)) , 0.0      );
67 //  NSPoint       pointC = NSMakePoint( (cw - (ch / 2)) , ch       );
68     NSPoint       pointD = NSMakePoint( (ch / 2)        , ch       );
69     NSPoint       lCtr   = NSMakePoint( (ch / 2)        , (ch / 2) );
70     NSPoint       rCtr   = NSMakePoint( (cw - (ch / 2)) , (ch / 2) );
71     float         alpha  = 0.35;
72     
73     [path moveToPoint:pointA];
74     [path lineToPoint:pointB];
75     [path appendBezierPathWithArcWithCenter:rCtr
76                                      radius:radius
77                                  startAngle:270.0
78                                    endAngle:90.0];
79     [path lineToPoint:pointD];
80     [path appendBezierPathWithArcWithCenter:lCtr
81                                      radius:radius
82                                  startAngle:90.0
83                                    endAngle:270.0];
84
85     if ( [self isHighlighted] ) {
86         alpha = 0.50;
87     }
88
89     [[NSColor colorWithCalibratedWhite:0.0 alpha:alpha] set];
90     [path fill];
91 }
92
93
94 @end