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