Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Programmer's Guide to MacApp / Part 2 - Working With MacApp
Chapter 15 - Working With the Mouse


Overview

Whenever a user presses or releases the mouse button, MacApp receives a Toolbox event describing the action. In some cases, MacApp handles the event for you; in others, it passes the event on to your code. For example, MacApp takes care of a click in the Apple menu, but your application handles the event when a user clicks in the content area of your window.

Any class that descends from TView or TBehavior can handle a mouse event by overriding the DoMouseCommand method. Your application can handle mouse events directly in subclasses of TView and through attached behavior objects in subclasses of TEventHandler, including TApplication, TDocument, and TWindow. Mouse events are most commonly handled by objects of the view class.

A view object's DoMouseCommand method handles a mouse event by creating a mouse-tracking command object and posting it to the command queue. MacApp provides the TTracker class for responding to user actions with the mouse. The TTracker class supplies methods for tracking the cursor, constraining cursor movement, and providing user feedback.

In the TTracker class, the TrackConstrain, TrackFeedback, and TrackMouse methods just call methods of the same name in the command's view. This allows MacApp's control view classes, such as TButton and TCheckBox, to track the mouse within the view object. More commonly, you handle drawing, selecting, or dragging with the mouse by defining a subclass of TTracker and overriding the TrackConstrain, TrackFeedback, and TrackMouse methods. To make the command undoable, you override the DoIt, UndoIt, and RedoIt methods or have the TrackMouse method post an undoable command when it has finished tracking.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
25 JUL 1996