More NSStatusItem setTarget / setAction
More NSStatusItem setTarget / setAction
- Subject: More NSStatusItem setTarget / setAction
- From: David Blanton <email@hidden>
- Date: Wed, 18 Jun 2003 18:31:14 -0600
Adding to my original post:
The function <iconClicked> is never called so I believe the error might be
in the setting of the target or the action. How does one check the result
of
[theItem setTarget:controller]
since this is void? And how does on check the result of
[theItem setAction:@selector(iconClicked)]
Which is also void.
I am dazed and confused.
--------------------------------------------------------
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.
_______________________________________________
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.