For example, if you move the mouse cursor from one tracking rectangle to another tracking rectangle in a view and back, the order of events (as messages) could be: initializer is invoked, the view is not yet associated with a window, so the tracking rectangle cannot yet be added to the window’s list.Thus the best place to add tracking rectangles initially is in the method.
If you only want to receive mouse-moved messages while the mouse is over your view, you should turn them off again when a mouse-tracking session completes. However, you should also set the window state back to what it was before you turned on mouse-moved events to ensure that the window does not stop receiving mouse-moved events if it wants them for other purposes. If you use tracking rectangles, you should be sure to remove and reestablish them when you change the frame rectangle of the view object that contains them.If you’re creating a custom subclass of You should also remove the tracking rectangle when your view is removed from its window, which can happen either because the view is moved to a different window, or because the view is removed as part of deallocation.One place to do this is the One common use of tracking rectangles is to change the cursor image over different types of graphic elements.Mouse-tracking messages are sent to an object when the mouse pointer (without a mouse button being pressed) enters and exits a region of a window.This region is known as a tracking rectangle or tracking area.
Mouse tracking enables the view owning the region to respond, for example, by drawing a highlight color or displaying a tool tip.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 instead.The sections in this chapter describe how you set up tracking rectangles and respond to mouse-tracking events.They also discuss how to specify and manage the rectangles for cursor-update events.Important: The proper order of mouse-entered and mouse-exited events received by tracking rectangles in an application cannot be guaranteed.