• 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
Re: disabling right-mouse click and ctrl+click?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: disabling right-mouse click and ctrl+click?


  • Subject: Re: disabling right-mouse click and ctrl+click?
  • From: Khusro Jaleel <email@hidden>
  • Date: Thu, 03 Mar 2005 16:26:33 +0000

Thanks so much Robert! I really appreciate that you provided some code to help me do this. I understand what the code does so I just stuck it into a subclass of NSTextView that the project was already using and that did the trick.

I looked at field editors and read the documentation but I couldn't figure out that if I did implement my own field editor, which methods would I override. Maybe it's a stupid question but I am new enough to cocoa that I didn't have a clue how to proceed from there.

Thanks again for your example,
Khusro

Robert Clair wrote:


CTRL+click still generates a right-click, how do I catch it and discard it?


First off, this isn't true. It is a subtle point, but a left click with the control key depressed generates an NSLeftMouseDown event with the NSControlKeyMask bit set in the modifier flags and a right click generates a NSRightMouseDown event. The reason that they appear to be the same is that, by default, the event dispatching mechanism in the window grabs both and calls

      -[NSView menuForEvent:]

for the view that is receiving events. The default implementation of -menuForEvent: returns the context menu. (To see that this is true, implement a do-nothing version of -rightMouseDown in a subclass of NSView. Notice that it gets called - and you get no context menu - for a right click, but it isn't called for a control click.)

To remove the cut and paste you could make a subclass for NSTextField or NSTextView and override -menuForEvent. Grab the menu, remove the cut and paste items and pass it on.

- (NSMenu *)menuForEvent:(NSEvent *)event
{
   NSMenu* contextMenu = [super menuForEvent: event];

   // remove Cut

   int itemIndex = [contextMenu indexOfItemWithTitle: @"Cut"];

   if ( itemIndex >= 0 )
     {
        [contextMenu removeItemAtIndex: itemIndex];
     }

  // repeat for anything else you don't want

  return contextMenu;
}

If you don't want any menu, just return nil.



Bob Clair

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:


This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: disabling right-mouse click and ctrl+click? (From: Robert Clair <email@hidden>)

  • Prev by Date: Re: keyDown:not receiving Command + key events, space bar, left/right arrows
  • Next by Date: controller class and window
  • Previous by thread: Re: disabling right-mouse click and ctrl+click?
  • Next by thread: disabling right-mouse click and ctrl+click?
  • Index(es):
    • Date
    • Thread