osx - NSWindow.contentView.hittest() Doesn't Reach Subviews of NSOutlineView -
my app's window has splitview 3 panes; leftmost pane hosts view-based outline view.
when click somewhere on outline view, want determine bottom-most subview in hierarchy clicked. is, row, cell, , subview (control) of cell clicked.
i tried overriding mousedown(with:) on hosting view controller, isn't called; suspected outline view somehow hogging event instead decided override method directly on nsoutlineview subclass itself. works. however, there can not go further down hierarchy outline view itself:
class myoutlineview: nsoutlineview {
override func mousedown(with event: nsevent) { if let view = self.window?.contentview?.hittest(event.locationinwindow) { swift.print("\(view.classname)") } } ...prints:
mymodule. myoutlineview
the documentation hittest() reads:
returns farthest descendant of view in view hierarchy (including itself) contains specified point, or nil if point lies outside view. method used nswindow object determine view should receive mouse-down event. you’d need invoke method, might want override have view object hide mouse-down events subviews. method ignores hidden views.
how can hit-test topmost subviews of outline view?
mousedown(with:) called on views, not on controllers. control inside outline view handles mousedown.
but if want find control, yes, -[nstableview(nstableviewrowheadersupport) hittest:] messes things up. workaround: row , column, cell view , call hittest on cell view.
override func mousedown(with event: nsevent) { let localpoint = self.convert(event.locationinwindow, from: nil) let column = self.column(at: localpoint) let row = self.row(at: localpoint) if column >= 0 && row >= 0 { if let cellview = self.view(atcolumn: column, row: row, makeifnecessary: false) { if let cellsuperviewpoint = cellview.superview?.convert(localpoint, from: self) { if let view = cellview.hittest(cellsuperviewpoint) { swift.print("\(view.classname)") } } } } }
Comments
Post a Comment