1 #import "ITStatusItem.h"
2 #import <CoreServices/CoreServices.h>
4 @interface ITStatusItemMenuProxy : NSProxy {
5 id <ITStatusItemMenuProvider> menuProvider;
6 ITStatusItem *statusItem;
7 AbsoluteTime cachedTime;
11 - (id)initWithMenuProvider:(id <ITStatusItemMenuProvider>)provider statusItem:(ITStatusItem *)item;
15 @implementation ITStatusItemMenuProxy
17 + (BOOL)respondsToSelector:(SEL)aSelector {
18 if (![super respondsToSelector:aSelector]) {
19 return [NSMenu respondsToSelector:aSelector];
24 - (id)initWithMenuProvider:(id <ITStatusItemMenuProvider>)provider statusItem:(ITStatusItem *)item {
25 menuProvider = [provider retain];
26 statusItem = [item retain];
27 cachedTime = UpTime();
32 - (void)forwardInvocation:(NSInvocation *)anInvocation {
33 AbsoluteTime diff = SubAbsoluteFromAbsolute(UpTime(),cachedTime);
35 if (!menu || diff.lo > 1000000) {
37 menu = [[menuProvider menuForStatusItem:statusItem] retain];
38 cachedTime = UpTime();
41 [anInvocation setTarget:menu];
42 [anInvocation invoke];
45 - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
46 return [NSMenu instanceMethodSignatureForSelector:aSelector];
52 [menuProvider release];
58 @class NSStatusBarButton;
60 @interface NSStatusItem (ITStatusItemHacks)
61 - (id)_initInStatusBar:(NSStatusBar *)statusBar withLength:(float)length withPriority:(int)priority;
62 - (NSStatusBarButton *)_button;
65 @protocol _ITStatusItemNSStatusBarButtonMethods
66 - (NSMenu *)statusMenu;
67 - (void)setStatusMenu:(NSMenu *)menu;
70 @protocol _ITStatusItemNSStatusItemPantherCompatability
71 - (void)setAlternateImage:(NSImage *)image;
72 - (NSImage *)alternateImage;
75 @implementation ITStatusItem
77 static BOOL _ITStatusItemShouldKillShadow = NO;
80 if ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_1) && (floor(NSAppKitVersionNumber) <= 663.6)) {
81 _ITStatusItemShouldKillShadow = YES;
85 - (id)initWithStatusBar:(NSStatusBar *)statusBar withLength:(float)length {
86 return [self _initInStatusBar:statusBar withLength:length withPriority:1000];
89 - (id)_initInStatusBar:(NSStatusBar *)statusBar withLength:(float)length withPriority:(int)priority {
90 if ((self = [super _initInStatusBar:statusBar withLength:length withPriority:priority])) {
93 if (_ITStatusItemShouldKillShadow) {
94 [[(NSButton *)[self _button] cell] setType:NSNullCellType];
96 [self setHighlightMode:YES];
101 - (NSImage *)alternateImage {
102 if ([super respondsToSelector:@selector(alternateImage)]) {
103 return [(id <_ITStatusItemNSStatusItemPantherCompatability>)super alternateImage];
105 return [(NSButton *)[self _button] alternateImage];
108 - (void)setAlternateImage:(NSImage*)image {
109 if ([super respondsToSelector:@selector(setAlternateImage:)]) {
110 [(id <_ITStatusItemNSStatusItemPantherCompatability>)super setAlternateImage:image];
113 [(NSButton *)[self _button] setAlternateImage:image];
116 - (id <ITStatusItemMenuProvider>)menuProvider {
117 return _menuProvider;
120 - (void)setMenuProvider:(id <ITStatusItemMenuProvider>)provider {
121 [_menuProxy autorelease];
123 _menuProvider = provider;
125 _menuProxy = [[ITStatusItemMenuProxy alloc] initWithMenuProvider:_menuProvider statusItem:self];
126 [(id <_ITStatusItemNSStatusBarButtonMethods>)[self _button] setStatusMenu:_menuProxy];
128 [self setMenu:[self menu]];
133 [_menuProxy release];