An instance of the NSTrackingArea class defines an area of a view that is responsive to the movements of the mouse. When the mouse cursor enters this area, moves around in it, and leaves it, the Application Kit sends (depending on the options specified) mouse-tracking, mouse-moved, and cursor-update messages to a designated object.
Important: The NSTrackingArea class was introduced in Mac OS X v10.5. For a discussion of the API used for mouse tracking and cursor updating in earlier releases, see the appendix “Mouse-Tracking and Cursor-Update Events.” Also see “Compatibility Issues,” below, for a discussion of the current behavior of deprecated methods.
The Application Kit sends the mouse-tracking messages mouseEntered: and mouseExited: to an object when the mouse cursor enters and exits a region of a window. Mouse tracking enables the view owning the region to respond, for example, by drawing a highlight color or displaying a tool tip. The Application Kit also sends mouseMoved: messages to the object if NSMouseMoved types of events are requested. Cursor-update events are a special kind of mouse-tracking event that the Application Kit handles automatically. When the mouse pointer enters a cursor rectangle, the Application Kit displays a cursor image appropriate to the type of view under the rectangle; for example, when a mouse pointer enters a text view, an I-beam cursor is displayed.
The sections in this chapter describe how to create NSTrackingArea objects, attach them to views, respond to related events, and manage the objects when changes in view geometry occur.
Creating an NSTrackingArea Object
Managing a Tracking-Area Object
Responding to Mouse-Tracking Events
Managing Cursor-Update Events
Compatibility Issues
Last updated: 2007-03-16