0

I have subclassed NSComboBox for a number of reasons, including a strategy for displaying contextual menus without the OS adding arcane things to them. (“Add to iTunes as a spoken track”???) Here are my mouse event methods:

public override func    mouseDown (event: NSEvent) 
  { NSLog("mouseDown")
    if NSEvent.modifierFlags().contains(.ControlKeyMask)     
      { self.rightMouseDown(event) }  
    else  
      { super.mouseDown(event) }
  }

public override func    rightMouseDown (event: NSEvent) 
  { NSLog("rightMouseDown")
    super.menu?.delegate = self
    super.menu?.allowsContextMenuPlugIns = false
    super.menu?.popUpMenuPositioningItem(nil, atLocation:
       self.convertPoint(event.locationInWindow, fromView: nil), inView: self)
  }

The rightMouseDown method does the last-second menu configuration I want. And I think the (left) mouseDown method would also work (it’s there only because ctrl-left-click is a traditional alternate to right-click), except that with the control key down it never sees the mouse event. The event seems to get to the superclass by going around rather than through my subclass, because NSComboBox does display a menu, just not the one I want (and the menu delegate isn’t right, etc).

I suspect there is some kind of legacy propagation path for ctrl-left-clicks, from the era when Apple mice had only one button. If I knew where these events were directed (I don’t think they’re going to my NSPanel), I might be able to intercept them. Does anyone know where they go? Is there something in NSEvent documentation I’m staring at and not seeing?

Jeff J
  • 139
  • 8
  • When did the era of single button mice end? o_O – l'L'l Jun 06 '16 at 15:55
  • I don’t remember exactly: the late ’90s, perhaps? I do remember that Apple was puzzlingly late in offering a two-button mouse. – Jeff J Jun 07 '16 at 12:57
  • I wouldn't rely on people having a two-button mouse, since the one-button is still the norm. – l'L'l Jun 07 '16 at 17:46

0 Answers0