Huge audit of ITKit, mostly everything has been updated to current coding
[ITKit.git] / ITStatusItem.m
old mode 100755 (executable)
new mode 100644 (file)
index 5e517a0..b758d5c
@@ -1,99 +1,54 @@
 #import "ITStatusItem.h"
 
-/*************************************************************************/
-#pragma mark -
-#pragma mark EVIL HACKERY
-/*************************************************************************/
+@class NSStatusBarButton;
 
-// This stuff is actually implemented by the AppKit.
-// We declare it here to cancel out warnings.
-
-@interface NSStatusBarButton : NSButton
+@interface NSStatusItem (ITStatusItemHacks)
+- (id)_initInStatusBar:(NSStatusBar *)statusBar withLength:(float)length withPriority:(int)priority;
+- (NSStatusBarButton *)_button;
 @end
 
-@interface NSStatusItem (HACKHACKHACKHACK)
-- (id) _initInStatusBar:(NSStatusBar*)statusBar
-             withLength:(float)length
-           withPriority:(int)priority;
-- (NSStatusBarButton*) _button;
-@end
-
-/*************************************************************************/
-#pragma mark -
-#pragma mark PRIVATE METHOD DECLARATIONS
-/*************************************************************************/
-
-@interface ITStatusItem (Private)
-- (void) setSmallTitle:(NSString*)title;
+@protocol _ITStatusItemNSStatusItemPantherCompatability
+- (void)setAlternateImage:(NSImage *)image;
+- (NSImage *)alternateImage;
 @end
 
 @implementation ITStatusItem
 
-/*************************************************************************/
-#pragma mark -
-#pragma mark INITIALIZATION METHODS
-/*************************************************************************/
+static BOOL _ITStatusItemShouldKillShadow = NO;
 
-- (id)initWithStatusBar:(NSStatusBar*)statusBar withLength:(float)length
-{
-    if ( ( self = [super _initInStatusBar:statusBar
-                               withLength:length
-                             withPriority:1000] ) ) {
-                             
-        //Eliminate the fucking shadow...
-        [[[self _button] cell] setType:NSNullCellType];
-        
-        //Be something other than a dumbshit about highlighting...
-        [self setHighlightMode:YES];
-    }
-    return self;
++ (void)initialize {
+       if ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_1) && (floor(NSAppKitVersionNumber) <= 663.6)) {
+               _ITStatusItemShouldKillShadow = YES;
+       }
 }
 
-
-/*************************************************************************/
-#pragma mark -
-#pragma mark ACCESSOR METHODS
-/*************************************************************************/
-
-- (NSImage*) alternateImage {
-    return [[self _button] alternateImage];
+- (id)initWithStatusBar:(NSStatusBar *)statusBar withLength:(float)length {
+       return [self _initInStatusBar:statusBar withLength:length withPriority:1000];
 }
 
-- (void) setAlternateImage:(NSImage*)image {
-    [[self _button] setAlternateImage:image];
-}
-
-- (void) setImage:(NSImage*)image {
-    [super setImage:image];
-    if ([self title]) {
-        [self setSmallTitle:[self title]];
-    }
-}
-
-- (NSString*) title {
-    if ([self image]) {
-        return [[self attributedTitle] string];
-    } else {
-        [super title];
+- (id)_initInStatusBar:(NSStatusBar *)statusBar withLength:(float)length withPriority:(int)priority {
+    if ((self = [super _initInStatusBar:statusBar withLength:length withPriority:priority])) {
+               if (_ITStatusItemShouldKillShadow) {
+                       [[(NSButton *)[self _button] cell] setType:NSNullCellType];
+               }
+        [self setHighlightMode:YES];
     }
+    return self;
 }
 
-- (void) setTitle:(NSString*)title {
-    [super setTitle:title];
-    if ([self image]) {
-        [self setSmallTitle:[self title]];
-    }
+- (NSImage *)alternateImage {
+       if ([super respondsToSelector:@selector(alternateImage)]) {
+               return [(id <_ITStatusItemNSStatusItemPantherCompatability>)super alternateImage];
+       }
+       return [(NSButton *)[self _button] alternateImage];
 }
 
-/*************************************************************************/
-#pragma mark -
-#pragma mark PRIVATE METHODS
-/*************************************************************************/
-
-- (void) setSmallTitle:(NSString*)title {
-    NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:title attributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12.0] forKey:NSFontAttributeName]];
-    [self setAttributedTitle:attrTitle];
-    [attrTitle release];
+- (void)setAlternateImage:(NSImage*)image {
+       if ([super respondsToSelector:@selector(setAlternateImage:)]) {
+               [(id <_ITStatusItemNSStatusItemPantherCompatability>)super setAlternateImage:image];
+               return;
+       }
+    [(NSButton *)[self _button] setAlternateImage:image];
 }
 
-@end
+@end
\ No newline at end of file