Re: Make an NSButton send a message on right click
Re: Make an NSButton send a message on right click
- Subject: Re: Make an NSButton send a message on right click
- From: Andy Lee <email@hidden>
- Date: Fri, 23 Oct 2009 21:04:22 -0400
On Oct 23, 2009, at 2:42 PM, Kyle Sluder wrote:
On Fri, Oct 23, 2009 at 10:55 AM, Jens Alfke <email@hidden>
wrote:
Yup. Subclass NSButton, override -mouseDown: and check whether the
event
uses the right button. If so, do your thing; otherwise, call the
superclass
method.
This isn't going to work, because Alexander is using an NSMatrix.
This means NSButtonCells, not NSButtons.
You'll need to subclass NSMatrix.
I don't know anything about Minesweeper, but I imagine it's possible
you'll want the right-click behavior to include some of the logic of
left-click behavior. In particular:
* You typically want a control to do its thing on mouse-up, not mouse-
down.
* You might need to deal with the case where the mouse-up is on a
different cell than the mouse-down was on.
* You might want visual feedback for the cells that get dragged over
before the user releases the mouse.
There are two ways in which controls implement the click-drag-release
loop:
(1) Some controls override mouseDown: to process all mouse events up
to and including the final mouse-up.
(2) Other controls override the combination of mouseDown:,
mouseDragged:, and mouseUp:.
I don't know whether NSMatrix is case (1) or case (2), but I *think*
the following handles both cases:
* Add a flag in your NSMatrix subclass called lastClickWasRightClick,
or some such.
* Override mouseDown: to set lastClickWasRightClick to NO and call
[super mouseDown:].
* Override rightMouseDown: to set this flag to YES and *also* call
[super mouseDown:].
* Have the action method in your matrix's target check the value of
the flag.
I trust the list will let me know if the above is misguided or there's
a simpler solution. I admit an uneasy feeling because I haven't
actually tried this.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden