MouseTrapDoc.tioga
Ken Shoemake, May 16, 1989 3:11:02 am PDT
Jules Bloomenthal July 9, 1991 0:08 am PDT
MouseTrap
PCEDAR 2.0 — FOR INTERNAL XEROX USE ONLY
MouseTrap
Ken Shoemake
© Copyright 1988, 1990 Xerox Corporation. All rights reserved.
Abstract: MouseTrap allow clients to trap the mouse, by watching and adjusting its position.
Created by: Ken Shoemake
Maintained by: Jules Bloomenthal <Bloomenthal>
Keywords: Mouse, Screen, Trap, User Interface, Viewer
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

For Internal Xerox Use Only
Client Use
This interface defines procedures for trapping the mouse, that is, adjusting its position (and that of the cursor) depending on its location. A typical application is keeping the mouse inside a viewer while dragging. This can be done by:
 orgx, orgy, oppx, oppy: INTEGER;
 data: MouseTrap.BoxTrapData;
 [orgx, orgy] ← MouseTrap.UserToMouseCoords[self, 0, 0];
 [oppx, oppy] ← MouseTrap.UserToMouseCoords[self, self.cw-1, self.ch-1];
IF oppx < orgx THEN {swap: INTEGER ← oppx; oppx ← orgx; orgx ← swap};
IF oppy < orgy THEN {swap: INTEGER ← oppy; oppy ← orgy; orgy ← swap};
 data ← NEW[MouseTrap.BoxTrapDataRep ← [no, [orgx, orgy], [oppx, oppy]]];
 [] ← MouseTrap.SetTrap[[enabled: TRUE, proc: MouseTrap.BoxTrap, data: data]];
To stop trapping, typically upon a mouse up, simply:
 [] ← MouseTrap.UnsetTrap[];
An appropriate place for these calls is in the TIP NotifyProc. You may wish to consider claiming a viewer lock so the column can't be rearranged out from under your trap by some independent process opening or closing a viewer. So that a mouse up is certain to be noticed, you may wish to call InputFocus.CaptureButtons, though that probably isn't necessary. Traps (such as BoxTrap and RoundTrap) using MouseUpEscape should probably catch all mouse ups.
By supplying a custom trapping procedur the mouse may be confined to a fancier region than a rectangle or circle. Keep in mind, however, that whatever you do you should do quickly!
Sample client use is found in MouseTrapTestImpl.mesa.