Skip navigation.
 
mlRe: Non-Contextual Popup Menus using NSPopupButtonCell and attachPopupWithFrame or performClickWithFrame
FROM : Peter Ammon
DATE : Tue Jan 08 21:54:10 2008

On Jan 8, 2008, at 6:52 AM, Oliver Kurek wrote:

> Reading through the documentation regarding contextual popup menus, 
> Apple
> notes that the prefered method of popping up a non-contextual menu 
> is using
> an NSPopupButtonCell and using the attachPopupWithFrame:inView method.
>
> After attempting this on my own with little luck, and browing 
> Google, I
> found that others had issues with using 
> attachPopupWithFrame:inView, and
> suggested to use performClickWithFrame:inView instead. 
> Specifically, when
> using the former, no menu appears at all.  With the latter, the 
> menu pops
> up, but it does not appear at the position of the mouse pointer. 
> Instead,
> the menu appears to popup at roughtly the right horizontal position on
> screen, but always at the bottom edge of the view.
>
> The particular situation I have is an NSTextView that is 
> subclassed, which
> occasionally includes text formated as a link with a custom-handled 
> link
> object.  When the link is clicked, a menu is generated based on the 
> details
> of the link and popped up.
>
> Is there any way to have this menu pop up at the position of the mouse
> pointer?  Has anyone had success using attachPopupWithFrame:inView 
> rather
> than performClickWithFrame:inView?
>
> Any help would be greatly appreciated!


Hi Oliver,

With performClickWithFrame: inView:, the menu will pop up as if a 
popup button were positioned within the frame parameter, interpreted 
as a rect within the bounds coordinate space of the given view.  To 
pop up a menu where the user clicked, pass a 1x1 rect whose origin is 
the location of the event within the bounds of your view, as the 
frame parameter.

I hope that's clear,
-Peter

Related mailsAuthorDate
mlNon-Contextual Popup Menus using NSPopupButtonCell and attachPopupWithFrame or performClickWithFrame Oliver Kurek Jan 8, 15:52
mlRe: Non-Contextual Popup Menus using NSPopupButtonCell and attachPopupWithFrame or performClickWithFrame Peter Ammon Jan 8, 21:54