ITKit For MenuTunes
[ITKit.git] / ITStatusItem.m
1 #import "ITStatusItem.h"
2
3 /*************************************************************************/
4 #pragma mark -
5 #pragma mark EVIL HACKERY
6 /*************************************************************************/
7
8 // This stuff is actually implemented by the AppKit.
9 // We declare it here to cancel out warnings.
10
11 @interface NSStatusBarButton : NSButton
12 @end
13
14 @interface NSStatusItem (HACKHACKHACKHACK)
15 - (id)_initInStatusBar:(NSStatusBar*)statusBar
16              withLength:(float)length
17            withPriority:(int)priority;
18 - (NSStatusBarButton*)_button;
19 @end
20
21 /*************************************************************************/
22 #pragma mark -
23 #pragma mark PRIVATE METHOD DECLARATIONS
24 /*************************************************************************/
25
26 @interface ITStatusItem (Private)
27 - (void)setImage:(NSImage*)image;
28 - (NSString*) title;
29 - (void)setTitle:(NSString*)title;
30 - (void)setSmallTitle:(NSString*)title;
31 @end
32
33 @implementation ITStatusItem
34
35 /*************************************************************************/
36 #pragma mark -
37 #pragma mark INITIALIZATION METHODS
38 /*************************************************************************/
39
40 - (id)initWithStatusBar:(NSStatusBar*)statusBar withLength:(float)length
41 {
42     if ( ( self = [super _initInStatusBar:statusBar
43                                withLength:length
44                              withPriority:1000] ) ) {
45                              
46         //Eliminate the fucking shadow...
47         [[[self _button] cell] setType:NSNullCellType];
48         
49         //Be something other than a dumbshit about highlighting...
50         [self setHighlightMode:YES];
51     }
52     return self;
53 }
54
55
56 /*************************************************************************/
57 #pragma mark -
58 #pragma mark ACCESSOR METHODS
59 /*************************************************************************/
60
61 - (NSImage*)alternateImage {
62     return [[self _button] alternateImage];
63 }
64
65 - (void)setAlternateImage:(NSImage*)image {
66     [[self _button] setAlternateImage:image];
67 }
68
69 - (void)setImage:(NSImage*)image {
70     [super setImage:image];
71     if ( [self title] ) {
72         [self setTitle:[self title]];
73     } 
74 }
75
76 - (void)setTitle:(NSString*)title {
77     if ( [self image] && (title != nil) ) {
78         [self setSmallTitle:title];
79     } else {
80         [super setTitle:title];
81     }
82 }
83
84
85 /*************************************************************************/
86 #pragma mark -
87 #pragma mark PRIVATE METHODS
88 /*************************************************************************/
89
90
91
92 - (void)setSmallTitle:(NSString*)title {
93     NSAttributedString *attrTitle = [[[NSAttributedString alloc] initWithString:title attributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12.0] forKey:NSFontAttributeName]] autorelease];
94     [self setAttributedTitle:attrTitle];
95 }
96
97
98 @end