views:

254

answers:

3

Hi Fokes,

I have a question about the NSStatusItem for cocoa in mac osx. If you look at the mac app called snippets (http://snippetapp.com/ look @ the movie there). you will see that once you clicked your statusbar icon that a perfectly aligned view / panel or maybe even windows appears just below the icon.

My question is ... How to calculate the position to where to place your NSWindow just like this app does ?.

I have tried the following

1) Subclass NSMenu 2) Set the view popery for the first item of the menu (Worked but enough) 3) Using addSubview instead of icon to NSStatusItem this worked but could not get heigher then 20px

+3  A: 

Give the NSStatusItem a view, then get the frame of that view's window. This technically counts as UndocumentedGoodness, so don't be surprised if it breaks someday (e.g., if they start keeping the window offscreen instead).

I don't know what you mean by “could not get heigher then 20px”.

Peter Hosey
W00t !! that helped look @ this debug message 2009-08-19 22:15:43.199 PasteBin[14430:a0f] X:1118.000000 -- Y:1028.0000002009-08-19 22:15:43.203 PasteBin[14430:a0f] X:1118.000000 -- Y:1028.000000------ Code here --- - (void)drawRect:(NSRect)dirtyRect { // Drawing code here. NSLog(@"X:%f -- Y:%f", self.window.frame.origin.x, self.window.frame.origin.y);}- --- - - -- - -Thanks so much i think that you have solved the mystery for millions of developers right now thanks !.
Johnny Mast
A: 

It seems that this app uses Matt's MAAttachedWindow. There's an sample application with the same layout & position.

Nando Vieira
A: 

Is there any way of doing this without replacing the view? A custom view breaks some behaviour, it seems, even if I try to imitade an ordinary menu (like the menu not disappearing when clicking another status item.

I tried to create a custom view and swap it, get the frame, and swap back, but that doesn't seem to work:

-(NSRect)getFrame;
{   
    NSView * swap = [[statusItem view] retain]; // setView calls release on the current view?
    [statusItem setView:customView];

    NSRect frame = [customView getFrame]; // works perfectly
    [statusItem setView:swap]; // nothing happens :(

    return frame;
}
oskob