NSStatusItem setTarget / setAction
NSStatusItem setTarget / setAction
- Subject: NSStatusItem setTarget / setAction
- From: David Blanton <email@hidden>
- Date: Wed, 18 Jun 2003 16:24:26 -0600
I am trying to do some Cocoa in Carbon. Would someone be so kind as to
review my code because it does not do what I expect.
I am trying to add an NSStatusItem and the have a function called when the
NSStatusItem is clicked.
Any help is much appreciated.
--
David Blanton
"Cocoa FNG"
typedef OSStatus (*CallBackType)(int);
@interface Controller : NSObject {
CallBackType _callBack;
}
- (void)iconClicked:(id)sender;
- (void)setCallBack:(CallBackType)callBack;
+ (id)sharedController;
@end
static Controller *sharedController;
@implementation Controller
+ (Controller *)sharedController {
return sharedController;
}
- (id)init {
self = [super init];
sharedController = self;
return self;
}
- (void)setCallBack:(CallBackType)callBack {
_callBack = callBack;
}
- (void)iconClicked:(id)sender {
(*_callBack)(1);
}
@end
bool Coc_Init()
{
NSApplicationLoad();
if (NSApp) return true;
else return false;
}
bool Coc_SetTrayIcon(OSStatus (*callBack)(int))
{
NSAutoreleasePool *localPool;
Controller * controller;
localPool = [[NSAutoreleasePool alloc] init];
controller = [[Controller alloc] init];
[controller setCallBack: callBack];
NSStatusBar * statusBar = [NSStatusBar systemStatusBar];
NSStatusItem * theItem = [statusBar
statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];
[theItem setTitle: NSLocalizedString(@"MR",@"")];
[theItem setToolTip: NSLocalizedString(@"MediaRights v1.0A",@"")];
//[theItem setHighlightMode: YES];
[theItem setEnabled: YES];
// this does not seem to set the target and action correctly as iconClicked
// is never called
[theItem sendActionOn: NSLeftMouseUpMask];
[theItem setTarget: controller];
[theItem setAction: @selector(iconClicked)];
[localPool release];
return true;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.