X-Git-Url: http://git.ithinksw.org/ITKit.git/blobdiff_plain/32440a12defde03dcc52e42cff4aa6300d7d96fb..6c3280197bc36e3b5911e971bd8958352ed8aa4f:/ITStatusItem.m diff --git a/ITStatusItem.m b/ITStatusItem.m old mode 100755 new mode 100644 index 5e517a0..d4e078a --- a/ITStatusItem.m +++ b/ITStatusItem.m @@ -1,99 +1,114 @@ #import "ITStatusItem.h" -/*************************************************************************/ -#pragma mark - -#pragma mark EVIL HACKERY -/*************************************************************************/ +@interface ITStatusItemMenuProxy : NSProxy { + id menuProvider; + ITStatusItem *statusItem; +} -// This stuff is actually implemented by the AppKit. -// We declare it here to cancel out warnings. +- (id)initWithMenuProvider:(id )provider statusItem:(ITStatusItem *)item; -@interface NSStatusBarButton : NSButton @end -@interface NSStatusItem (HACKHACKHACKHACK) -- (id) _initInStatusBar:(NSStatusBar*)statusBar - withLength:(float)length - withPriority:(int)priority; -- (NSStatusBarButton*) _button; -@end +@implementation ITStatusItemMenuProxy -/*************************************************************************/ -#pragma mark - -#pragma mark PRIVATE METHOD DECLARATIONS -/*************************************************************************/ ++ (BOOL)respondsToSelector:(SEL)aSelector { + if (![super respondsToSelector:aSelector]) { + return [NSMenu respondsToSelector:aSelector]; + } + return YES; +} -@interface ITStatusItem (Private) -- (void) setSmallTitle:(NSString*)title; -@end +- (id)initWithMenuProvider:(id )provider statusItem:(ITStatusItem *)item { + menuProvider = [provider retain]; + statusItem = [item retain]; + return self; +} -@implementation ITStatusItem +- (void)forwardInvocation:(NSInvocation *)anInvocation { + NSMenu *temporaryMenu = [[menuProvider menuForStatusItem:statusItem] retain]; + [anInvocation setTarget:temporaryMenu]; + [anInvocation invoke]; + [temporaryMenu release]; +} -/*************************************************************************/ -#pragma mark - -#pragma mark INITIALIZATION METHODS -/*************************************************************************/ - -- (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; +- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { + NSMenu *temporaryMenu = [[menuProvider menuForStatusItem:statusItem] retain]; + NSMethodSignature *signature = [temporaryMenu methodSignatureForSelector:aSelector]; + [temporaryMenu release]; + return signature; } +- (void)dealloc { + [statusItem release]; + [menuProvider release]; + [super dealloc]; +} + +@end -/*************************************************************************/ -#pragma mark - -#pragma mark ACCESSOR METHODS -/*************************************************************************/ +@class NSStatusBarButton; -- (NSImage*) alternateImage { - return [[self _button] alternateImage]; +@interface NSStatusItem (ITStatusItemHacks) +- (id)_initInStatusBar:(NSStatusBar *)statusBar withLength:(float)length withPriority:(int)priority; +- (NSStatusBarButton *)_button; +@end + +@protocol _ITStatusItemNSStatusItemPantherCompatability +- (void)setAlternateImage:(NSImage *)image; +- (NSImage *)alternateImage; +@end + +@implementation ITStatusItem + +static BOOL _ITStatusItemShouldKillShadow = NO; + ++ (void)initialize { + if ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_1) && (floor(NSAppKitVersionNumber) <= 663.6)) { + _ITStatusItemShouldKillShadow = YES; + } } -- (void) setAlternateImage:(NSImage*)image { - [[self _button] setAlternateImage:image]; +- (id)initWithStatusBar:(NSStatusBar *)statusBar withLength:(float)length { + return [self _initInStatusBar:statusBar withLength:length withPriority:1000]; } -- (void) setImage:(NSImage*)image { - [super setImage:image]; - if ([self title]) { - [self setSmallTitle:[self 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; } -- (NSString*) title { - if ([self image]) { - return [[self attributedTitle] string]; - } else { - [super title]; - } +- (NSImage *)alternateImage { + if ([super respondsToSelector:@selector(alternateImage)]) { + return [(id <_ITStatusItemNSStatusItemPantherCompatability>)super alternateImage]; + } + return [(NSButton *)[self _button] alternateImage]; } -- (void) setTitle:(NSString*)title { - [super setTitle:title]; - if ([self image]) { - [self setSmallTitle:[self title]]; - } +- (void)setAlternateImage:(NSImage*)image { + if ([super respondsToSelector:@selector(setAlternateImage:)]) { + [(id <_ITStatusItemNSStatusItemPantherCompatability>)super setAlternateImage:image]; + return; + } + [(NSButton *)[self _button] setAlternateImage:image]; } -/*************************************************************************/ -#pragma mark - -#pragma mark PRIVATE METHODS -/*************************************************************************/ +- (id )menuProvider { + return _menuProvider; +} -- (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)setMenuProvider:(id )provider { + [_menuProvider autorelease]; + _menuProvider = [provider retain]; + if (provider) { + [self setMenu:[[ITStatusItemMenuProxy alloc] initWithMenuProvider:_menuProvider statusItem:self]]; + } else { + [self setMenu:nil]; + } } -@end +@end \ No newline at end of file