Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive mouse clicks in a NSTableCellView subclass?

I have subclassed NSTableCellView to do some custom drawing. When the containing NSOutlineView's highlight style is set to None my view receives mouseDown events.
When I change the NSOutlineView's highlight style to Regular, my view no longer receives its mouseDown events.

How can I pass the mouseDown events to my view while keeping the outline view's highlight style to Regular?

like image 270
Mike T Avatar asked Dec 25 '22 15:12

Mike T


1 Answers

Apparently NSTableView overrides -hitTest: in order to implement the row selection/dragging/etc. functionality - that would explain why you're having no issues when the highlighting style is None.

As per the Apple Docs:

Specifying How Subviews Should Respond to Events

[...] If you create a table view subclass, you can override validateProposedFirstResponder:forEvent: to specify which views can become the first responder. In this way, you receive mouse events.

Or optionally.. if event handling is vital to your subclass: Why not create a NSControl subclass?
As per the same docs there's special handling for controls already implemented in the stock table view class.

like image 194
Jay Avatar answered Feb 20 '23 08:02

Jay