getting nsview to do something on right and middle click

Discussion in 'Mac Programming' started by Chirone, Nov 11, 2010.

  1. macrumors 6502

    Mar 2, 2009
    this may or may not be simple

    i want to know when the user has right or middle clicked on a view.

    you'd think it be as easy as just overriding the -(void)rightMouseDown: method... but it doesn't trigger... :confused:

    i thought maybe i have to make - (void)acceptsFirstMouse: return YES, but that method is never called

    i even tried overriding the - (NSMenu*)menuForEvent: and + (NSMenu*)defaultMenu methods but those never get called either.

    and yes, the view is at the top and it is the first responder. It responds to mouseDown: and it's set up to respond to mouseMoved:

    what am I missing?
  2. Moderator emeritus


    Jun 15, 2000
    Post your code.

    I made a new empty project, rightMouseDown: and mouseDown: get called just fine with no extra code.

    What OS?
  3. thread starter macrumors 6502

    Mar 2, 2009
    i made an empty project as well and i could right click and pick up the event

    makes me wonder what happened in the bigger project.

    in the bigger project the view is a subview of a view that's inside a clipview of a scrollview.

    upon further experiments i've found that the view that should be receiving right clicks will indeed receive them but only if i don't add the two subviews that are sitting on it.

    However, this doesn't make much sense to me as it receives mouseDown events easily and the two subviews don't even cover the entire view that is meant to receive right clicks.

    the two little subviews also have no code that passes on the mouse events to their super view...
  4. macrumors G5


    Nov 25, 2005

    Right mouse clicks only go to the topmost view and are not passed along the responder chain.
  5. thread starter macrumors 6502

    Mar 2, 2009

Share This Page