views:

141

answers:

1

I'm trying to implement some rudimentary tabs in a Cocoa editor I'm working on. I am using an NSSegmentedControl and adding segments to it as tabs. I'm using a custom NSSegmentedCell subclass for the tabs to draw a little 'x' icon next to the text for closing tabs and so far it's been going pretty smooth.

However, I cannot figure out how to actually process mouse events for the tabs to check if someone moused over (or clicked) the 'x' icon. I tried overriding "mouseMoved" in my NSSegmentedControl subclass, but for some odd reason it stops getting called when I add a new segment to it (I set "setAcceptsMouseMovedEvents" to yes in awakeFromNib, do I have to also set it somewhere else??). NSSegmentedCells, being NSCell subclasses seem to not have any mouse event processing, aside from mouse tracking, which gets triggered only when the control is clicked.

So the question is, how would I properly process mouse events, either in the NSSegmentedControl or in the NSSegmentedCell subclass?

+1  A: 

Take a look at NSTrackingArea. You can add a tracking area to your NSSegmentedControl and get mouse-entered events on that to highlight the close button.

As for getting the click events, you're probably best off using a separate NSActionCell subclass for the close button and do some hit testing there.

Jim Puls