• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Making a button show a menu when clicked
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Making a button show a menu when clicked


  • Subject: Making a button show a menu when clicked
  • From: Matt Gemmell <email@hidden>
  • Date: Sat, 25 Jan 2003 19:08:29 +0000

Hi folks,

Just for fun, I'm currently trying to duplicate the pulldown NSToolbarItems in Keynote (i.e. an NSToolbarItem which when clicked shows a menu below itself), such as the "Masters", "View" and "Shapes" items.

I've tried two approaches:

1. An NSView subclass which uses [NSMenu +popUpContextMenu:withEvent:forView:] in its -mouseDown handler.

2. An NSPopUpButton (pulldown) subclass which overrides -drawRect:.

Both work reasonably well, but not without problems:

1. The first method does not position the menu consistently, since it's just popping up a menu as if the user has control-clicked. I want the menu to always appear such that its top-left is just below the view's bottom-left point; i.e. the way that a menu appears relative to its title in the menubar.

2. Both methods don't perform highlighting of the image (the usual grey semi-transparent overlay which indicates a control is active). Similarly, they don't dim when disabled.

Accordingly, I have a couple of questions:

1. To correctly position the menu when using +popUpContextMenu:, should I construct an NSEvent (a mouse event) for the withEvent: parameter, and pass in an appropriate location value? Are there any caveats to be aware of when doing this? This method assumes that the offset of a context menu from the mouseDown point will never change in future OS versions. It doesn't feel particularly elegant.

2. If I instead use my NSPopUpButton subclass, I need to manually dim and highlight it. To do so, I need to know what colours and opacity fractions the system uses to do dimming and highlighting respectively (from the point of view of this eventually being in an NSToolbar). Are there methods, perhaps on NSColor, to obtain these? I thought that +controlTint might be what I was looking for, but I'm not at all sure.

Any thoughts would be much appreciated. Thanks for reading. :)

Best,
-Matt

--
Matt Gemmell
Scotland Software
http://www.scotlandsoftware.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • (solved) Making a button show a menu when clicked
      • From: Matt Gemmell <email@hidden>
  • Prev by Date: Converting CGShieldingWindowID() to NSWindow?
  • Next by Date: Re: NSBrowser: so very, very broken
  • Previous by thread: Re: Beginner question - Cocoa outlet using a method
  • Next by thread: (solved) Making a button show a menu when clicked
  • Index(es):
    • Date
    • Thread