BadmintonCat
BadmintonCat

Reputation: 9576

Disabling the NSTableView row focus ring

How do you disable the focus ring around an NSTableView row when the user right-clicks on it? I can't get it to disappear. Setting focus ring of an individual NSTableViewCell in the table to None has no effect.

enter image description here

Upvotes: 2

Views: 1722

Answers (3)

eonil
eonil

Reputation: 85955

If your goal is just displaying a contextual menu, you also can try this.

  • Wrap the NSOutlineView within another NSView.
  • Override menuForEvent method on the wrapper view.
  • Do not set menu on outline-view.

Now the wrapper view shows the menu instead of your outline-view, so it won't show the focus ring. See How do you add context senstive menu to NSOutlineView (ie right click menu) for how to find a node at the menu event.

Upvotes: 0

mangerlahn
mangerlahn

Reputation: 4966

New:

Here is how I did it. You can handle the menu manually. Subclass NSTableRowView or NSTableCellView, then use rightMouseDown: and mouseDown: (check for control key) and then notify your tableViewController (notification or delegate) of the click. Don't forget to pass the event as well, then you can display the menu with the event on the table view without the focus ring. The above answer is easier, but it may not pass the review, as the author mentioned. Plus you can show individual menu items for each row (if you have different sorts of views)

Old:

I think the focus ring is defined by NSTableRowView, not NSTableCellView, because it is responsible for the complete row. Try to change the focus ring there. You can subclass NSTableRowView and add it to the tableView via IB or NSTableViewDelegate's method:

- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row

Upvotes: 2

Renfei Song
Renfei Song

Reputation: 2960

Subclass the table view and implement the following method:

- (void)drawContextMenuHighlightForRow:(NSInteger)row {
    // do nothing
}

Note:

  1. The blue outline is not the focus ring.
  2. This is an undocumented private method Apple uses to draw the outline. Providing an empty implementation will prevent anything from being drawn, but I am not 100% sure that whether it can pass the review.

Upvotes: 3

Related Questions