tags:

views:

38

answers:

1

How can I get the on-screen location of a button in a toolbar? That is getting the rectangle frame of an NSToolbarItem? The [NSToolbarItem view] method seems to always return nil whenever the toolbar item is only a simple action button and thus I couldn't use the normal NSView methods to pinpoint the toolbar button's on-screen position.

Background

I'm trying to use Matt Gemmell's MAAttachedWindow component to point to a specific toolbar button. The component requires an NSPoint object to "point" the user to a location on the screen.

Thanks in advance.

+1  A: 

I happened to have the same kind of problem. Although I wouldn't say I solved it, I found a way that at least works for my scenario... In my ToolbarItem action I fetch the current mouse location - it proved to be sufficient in this case. An example implementation might look like this:

- (IBAction)showOverlay:(id)sender {
    NSPoint clickedPoint = [self.window mouseLocationOutsideOfEventStream];
    self.overlayController = [[MyOverlayController alloc] initAtPoint:clickedPoint];
}
Tobidobi
Hi Tobidobi,From the looks of it your solution is applicable when the user actually clicks the button, isn't it?What if the problem is to put a "click here" signpost? That is the user haven't clicked on the toolbar button.Thanks
adib