• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSStatusItem setTarget / setAction
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSStatusItem setTarget / setAction
      • From: Daniel Jalkut <email@hidden>
  • Prev by Date: Re: control delegate (NSTextField)
  • Next by Date: Re: NSStatusItem setTarget / setAction
  • Previous by thread: Re: control delegate (NSTextField)
  • Next by thread: Re: NSStatusItem setTarget / setAction
  • Index(es):
    • Date
    • Thread