5e517a0b55f2caccb6e92c24dbe27e55a059dc7a
[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) setSmallTitle:(NSString*)title;
28 @end
29
30 @implementation ITStatusItem
31
32 /*************************************************************************/
33 #pragma mark -
34 #pragma mark INITIALIZATION METHODS
35 /*************************************************************************/
36
37 - (id)initWithStatusBar:(NSStatusBar*)statusBar withLength:(float)length
38 {
39     if ( ( self = [super _initInStatusBar:statusBar
40                                withLength:length
41                              withPriority:1000] ) ) {
42                              
43         //Eliminate the fucking shadow...
44         [[[self _button] cell] setType:NSNullCellType];
45         
46         //Be something other than a dumbshit about highlighting...
47         [self setHighlightMode:YES];
48     }
49     return self;
50 }
51
52
53 /*************************************************************************/
54 #pragma mark -
55 #pragma mark ACCESSOR METHODS
56 /*************************************************************************/
57
58 - (NSImage*) alternateImage {
59     return [[self _button] alternateImage];
60 }
61
62 - (void) setAlternateImage:(NSImage*)image {
63     [[self _button] setAlternateImage:image];
64 }
65
66 - (void) setImage:(NSImage*)image {
67     [super setImage:image];
68     if ([self title]) {
69         [self setSmallTitle:[self title]];
70     }
71 }
72
73 - (NSString*) title {
74     if ([self image]) {
75         return [[self attributedTitle] string];
76     } else {
77         [super title];
78     }
79 }
80
81 - (void) setTitle:(NSString*)title {
82     [super setTitle:title];
83     if ([self image]) {
84         [self setSmallTitle:[self title]];
85     }
86 }
87
88 /*************************************************************************/
89 #pragma mark -
90 #pragma mark PRIVATE METHODS
91 /*************************************************************************/
92
93 - (void) setSmallTitle:(NSString*)title {
94     NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:title attributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12.0] forKey:NSFontAttributeName]];
95     [self setAttributedTitle:attrTitle];
96     [attrTitle release];
97 }
98
99 @end