views:

23

answers:

1

Hi,

I'm trying to show a pop up menu on mouse down on a button. The button should appear pressed while mouse down, and be "un pressed" on mouse up regardless of any of the menu item been selected. Similar to the Expose/Space Preference panel "+" button for adding application.

So far I tried 3 methods:

  1. Sent action when button is click. But here the pop up menu appear on mouse up instead of mouse down

  2. Subclass NSButton and overwrite mouseDown:. The pop up menu appear on mouse down, I can select any of the menu item. But when the pop up menu is gone, the button appeared pressed. Hence I need to click once again to "un press" the button before I can get the same action again.

  3. NSEvent addLocalMonitorForEventsMatchingMask. Similar behavior to 2.

Any suggestion? I guess method 2 or 3 is the right way, just need to "un press" the button on mouse up.

+2  A: 

As Peter mentioned, you can use an NSPopUpButton. What's not obvious is that you can configure the button's style, image, title, etc. just as you can with an NSButton.

Joshua Nozzi