• 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
I got a clue [was NSStatusItem setTarget / setAction]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I got a clue [was NSStatusItem setTarget / setAction]


  • Subject: I got a clue [was NSStatusItem setTarget / setAction]
  • From: David Blanton <email@hidden>
  • Date: Fri, 20 Jun 2003 15:49:58 -0600

OK,

I think the problem is not in the code but for some reason the Cocoa event
loop is not running or picking events, I suspect so because the +setToolTip
method or the +setHighlightMode don't do anything. That is, I can see the
text ("MR") in the system status bar, but the tooltip does not appear or the
item does not highlight. I think tooltips are implemented as actions to
mouse events.
I understand that 10.2 allows Cocoa and Carbon events on the same app to
coexist, so what is the problem?

So the question seems to be how to get an event in the Cocoa portion of a
Carbon app?

----------------------------------------------




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.

  • Prev by Date: Re: trivial question
  • Next by Date: Re: Class Cluster Confusion
  • Previous by thread: Fwd: crash in [NSDocument displayName]
  • Next by thread: Advice for Web front end
  • Index(es):
    • Date
    • Thread