Pop-up NSMenu without NSPopUpButton
-
How do I make an NSMenu act as a pop-up menu without the use of
NSPopUpButton? I see there are class methods to make it pop up as a
contextual menu, but I need it to pop up as a pop-up menu like
NSPopUpButton magically does, so that one item in the menu can be pre-
selected.
I've searched the archives, and have already tried calling
_NSGetCarbonMenu() for use with PopUpMenuSelect(), but the function is
always returning NULL, and even if this did work and didn't use
undocumented methods, it still won't work in 64-bit.
Nick Zitzmann
<http://www.chronosnet.com/> -
On Feb 11, 2008, at 2:35 PM, Nick Zitzmann wrote:> How do I make an NSMenu act as a pop-up menu without the use of
> NSPopUpButton? I see there are class methods to make it pop up as a
> contextual menu, but I need it to pop up as a pop-up menu like
> NSPopUpButton magically does, so that one item in the menu can be
> pre-selected.
>
> I've searched the archives, and have already tried calling
> _NSGetCarbonMenu() for use with PopUpMenuSelect(), but the function
> is always returning NULL, and even if this did work and didn't use
> undocumented methods, it still won't work in 64-bit.
To show a menu as if it were a popup menu, create an
NSPopUpButtonCell, call setMenu: on it, and then call [popupCell
performClickWithFrame: inView:].
The NSPopUpButtonCell can be entirely transient - you can create it
and destroy it in your mouseDown: method, for example.
-Peter -
On Feb 11, 2008 AD, at 3:47 PM, Peter Ammon wrote:> To show a menu as if it were a popup menu, create an
> NSPopUpButtonCell, call setMenu: on it, and then call [popupCell
> performClickWithFrame: inView:].
>
> The NSPopUpButtonCell can be entirely transient - you can create it
> and destroy it in your mouseDown: method, for example.
Thanks; that resolves the problem.
Nick Zitzmann
<http://www.chronosnet.com/>


