• 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
Re: Position of NSStatusItem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Position of NSStatusItem


  • Subject: Re: Position of NSStatusItem
  • From: Joachim Deelen <email@hidden>
  • Date: Fri, 23 Nov 2007 23:26:43 +0100

For me it's working flawlessly. I can't expose the complete code but I did something like the following

@interface StatusView : NSView {

	NSStatusItem *statusItem;			//!< The Status Area within the Menu-Bar
}
- (id)initWithStatusItem:(NSStatusItem*)statusBarItem;

@end

@implementation StatusView

- (id)initWithStatusItem:(NSStatusItem*)statusBarItem
{
self = [super initWithFrame:NSMakeRect(0.0, 2.0, [statusBarItem length], [[statusBarItem statusBar] thickness])];

if(self != nil) {
statusItem = statusBarItem;
[self setWantsLayer:YES];
[statusItem setView:self];
}
return self;
}


@end

In some other Class the View and the Status Item are created:

- (void)awakeFromNib
{
NSStatusBar *systemStatusBar = [NSStatusBar systemStatusBar];
statusItem = [systemStatusBar statusItemWithLength:[userDefaults integerForKey:kPWPreferenceSize]];
[statusView initWithStatusItem:statusItem];
}



I get the position on screen with the following:

NSRect rect = [[self.statusView window] frame];

The position is returned in absolute Screen coordinates. I really don't see your problem ;-(

BTW: I'm using Garbage-Collection so you won't see any retain/release or autorelease.

regards
Joachim


Am 22.11.2007 um 09:09 schrieb Peter Maurer:

The output is: "0.000000/0.000000" ... don't really know what's wrong with the code :-(

If you're willing to venture into undocumented goodness, you might want to have a look at this little category I wrote for a menu bar calendar that was supposed to appear right below its NSStatusItem years ago:


//--

@implementation NSStatusItem (PMForbiddenFruit)

	- (NSWindow*)window {
		if ([self respondsToSelector: @selector(_window)]) {
			return [self performSelector: @selector(_window)];
		}
		return nil;
	}

	- (NSRect)frameInScreenCoordinates {
		NSWindow *theWindow = [self window];
		if (theWindow) {
			return [theWindow frame];
		}
		return NSZeroRect;	// you better have a fallback strategy
	}

@end

//--

Peter.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Position of NSStatusItem
      • From: "[nexUmoja] Fabian Jäger" <email@hidden>
References: 
 >Position of NSStatusItem (From: "[nexUmoja] Fabian Jäger" <email@hidden>)
 >Re: Position of NSStatusItem (From: Joachim Deelen <email@hidden>)
 >Re: Position of NSStatusItem (From: Joachim Deelen <email@hidden>)
 >Re: Position of NSStatusItem (From: "[nexUmoja] Fabian Jäger" <email@hidden>)
 >Re: Position of NSStatusItem (From: Peter Maurer <email@hidden>)

  • Prev by Date: Re: Large progress indicators in Leopard
  • Next by Date: Re: -[NSManagedObjectContext save:] fails but gives no NSError
  • Previous by thread: Re: Position of NSStatusItem
  • Next by thread: Re: Position of NSStatusItem
  • Index(es):
    • Date
    • Thread