X-Git-Url: http://git.ithinksw.org/ITKit.git/blobdiff_plain/0fc44e732f98ed55cdd0d0914c4031ad9c005edc..6c3280197bc36e3b5911e971bd8958352ed8aa4f:/ITStatusItem.m?ds=inline diff --git a/ITStatusItem.m b/ITStatusItem.m index ea31d3a..d4e078a 100644 --- a/ITStatusItem.m +++ b/ITStatusItem.m @@ -1,5 +1,51 @@ #import "ITStatusItem.h" +@interface ITStatusItemMenuProxy : NSProxy { + id menuProvider; + ITStatusItem *statusItem; +} + +- (id)initWithMenuProvider:(id )provider statusItem:(ITStatusItem *)item; + +@end + +@implementation ITStatusItemMenuProxy + ++ (BOOL)respondsToSelector:(SEL)aSelector { + if (![super respondsToSelector:aSelector]) { + return [NSMenu respondsToSelector:aSelector]; + } + return YES; +} + +- (id)initWithMenuProvider:(id )provider statusItem:(ITStatusItem *)item { + menuProvider = [provider retain]; + statusItem = [item retain]; + return self; +} + +- (void)forwardInvocation:(NSInvocation *)anInvocation { + NSMenu *temporaryMenu = [[menuProvider menuForStatusItem:statusItem] retain]; + [anInvocation setTarget:temporaryMenu]; + [anInvocation invoke]; + [temporaryMenu release]; +} + +- (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 + @class NSStatusBarButton; @interface NSStatusItem (ITStatusItemHacks) @@ -51,4 +97,18 @@ static BOOL _ITStatusItemShouldKillShadow = NO; [(NSButton *)[self _button] setAlternateImage:image]; } +- (id )menuProvider { + return _menuProvider; +} + +- (void)setMenuProvider:(id )provider { + [_menuProvider autorelease]; + _menuProvider = [provider retain]; + if (provider) { + [self setMenu:[[ITStatusItemMenuProxy alloc] initWithMenuProvider:_menuProvider statusItem:self]]; + } else { + [self setMenu:nil]; + } +} + @end \ No newline at end of file