(solved) Making a button show a menu when clicked
(solved) Making a button show a menu when clicked
- Subject: (solved) Making a button show a menu when clicked
- From: Matt Gemmell <email@hidden>
- Date: Sun, 26 Jan 2003 13:21:31 +0000
On Saturday, January 25, 2003, at 07:08 pm, Matt Gemmell wrote:
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.
Solved by creating a new NSEvent with the same values as the received
event in mouseDown:, except that I passed in my own location value (the
origin of my NSButton subclass' frame), like this:
- (void)mouseDown:(NSEvent *)theEvent
{
[self highlight:YES];
NSEvent *click = [NSEvent mouseEventWithType:[theEvent type]
location:[self frame].origin
modifierFlags:[theEvent
modifierFlags]
timestamp:[theEvent timestamp]
windowNumber:[theEvent windowNumber]
context:[theEvent context]
eventNumber:[theEvent eventNumber]
clickCount:[theEvent clickCount]
pressure:[theEvent pressure]
];
[NSMenu popUpContextMenu:[self menu] withEvent:click forView:self];
}
That makes the menu appear in the proper position every time.
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.
Solved by using an NSButton subclass, setting it to have no border,
setting it to highlight by NSNoCellMask, and letting it draw itself -
thanks to Rudis Muiznieks.
Source to follow soon on my site.
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.