Re: Screen Coordinates of Menu. Use CTM? (was: Give menu keyboard focus)
Re: Screen Coordinates of Menu. Use CTM? (was: Give menu keyboard focus)
- Subject: Re: Screen Coordinates of Menu. Use CTM? (was: Give menu keyboard focus)
- From: Graham Cox <email@hidden>
- Date: Mon, 10 Oct 2011 13:47:23 +1100
This all sounds like a generally terrible idea.
Have you checked to see whether the Accessibility APIs can give you what you want?
If it's for some other purpose than accessibility, sounds like you're walking the slippery slope to hell…. ;)
--Graham
On 10/10/2011, at 1:26 PM, Jerry Krinock wrote:
> I changed the subject line because if I could just get the screen coordinates of my Status Item, my kludge for giving it keyboard focus looks like it will work.
>
> NSMenu inherits from NSObject, and as far as I can see give no clue regarding its location on the screen. NSStatusItem and NSStatusBar are likewise mum.
>
> However, the status item has an image. I subclassed NSImage, found that -drawInRect:fromRect:operation:fraction:respectFlipped:hints: is invoked. From reading the Cocoa Drawing Guide, it seems that the tx value of the current transformation matrix when this method is running is the x-coordinate that I'm looking for. So I subclassed NSImage…
>
> @implementation MyLocatableImage
>
> - (void)drawInRect:(NSRect)dstSpacePortionRect
> fromRect:(NSRect)srcSpacePortionRect
> operation:(NSCompositingOperation)op
> fraction:(CGFloat)requestedAlpha
> respectFlipped:(BOOL)respectContextIsFlipped
> hints:(NSDictionary *)hints {
> NSGraphicsContext* nsGraphicsContext = [NSGraphicsContext currentContext] ;
> CGContextRef aContext = [nsGraphicsContext graphicsPort] ;
> CGAffineTransform ctm = CGContextGetCTM(aContext) ;
> NSLog(@"The ctm: %f %f %f %f %f %f", ctm.a , ctm.b , ctm.c , ctm.d , ctm.tx , ctm.ty) ;
> [super drawInRect:dstSpacePortionRect
> fromRect:srcSpacePortionRect
> operation:op
> fraction:requestedAlpha
> respectFlipped:respectContextIsFlipped
> hints:hints] ;
> }
>
> @end
>
> Unfortunately, the matrix elements are NSLogged as:
> 1.000000 0.000000 -0.000000 1.000000 0.000000 22.000000
>
> which is obviously not what I'm looking for, since the the x-coordinate of my status item is about 850.
>
> The two 'Rect' parameters of that method give similar useless local coordinates.
>
> Is there any way to get the global/screen coordinates of a menu, an NSStatusItem in particular?
_______________________________________________
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