appletmouse.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletmouse.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletdefs.h"
00008 #include "appletmouse.h"
00009 
00010 
00011 tymouserecord mousestatus;
00012 
00013 
00014 boolean mousetrack (Rect r, tymousetrackcallback displaycallback) {
00015     
00016     /*
00017     hang out in this routine until the mouse button comes up.  return true if
00018     the mouse point is in the indicated rectangle when we return.
00019     
00020     7/17/90 DW: if the mouse wasn't down when we enter, return true.  this is
00021     a heuristic that may allow some mouse-dependent routines to be driven by
00022     a script.  we figure that if the mouse isn't down now, it never was down,
00023     and whether it's inside any particular rectangle is irrelevent.
00024     
00025     7/17/90 DW: add callback routine to display the object being tracked as
00026     the mouse moves in and out of the rectangle.  set it to nil if you don't
00027     need this feature.
00028     
00029     7/17/90 DW: only call the callback when the state of the object changes,
00030     assume display is correct when we're entered.
00031     */
00032     
00033     boolean flinrectnow;
00034     boolean flwasinrect;
00035     
00036     if (!StillDown ()) /*see comment above*/
00037         return (true);
00038     
00039     flwasinrect = true; /*at least for the first iteration of loop*/
00040     
00041     while (StillDown ()) { /*stay in holding pattern*/
00042     
00043         Point pt;
00044         
00045         GetMouse (&pt);
00046     
00047         flinrectnow = PtInRect (pt, &r);
00048         
00049         if (flinrectnow != flwasinrect) { /*state of object changed*/
00050         
00051             if (displaycallback != nil)
00052                 (*displaycallback) (flinrectnow);
00053             }
00054             
00055         flwasinrect = flinrectnow;
00056         } /*while*/
00057     
00058     return (flwasinrect);
00059     } /*mousetrack*/
00060 
00061 
00062 static short absint (short x) {
00063     
00064     if (x < 0)
00065         x = -x;
00066         
00067     return (x);
00068     } /*absint*/
00069     
00070     
00071 static short pointdist (Point pt1, Point pt2) {
00072     
00073     return (absint (pt1.h - pt2.h) + absint (pt1.v - pt2.v));
00074     } /*pointdist*/
00075 
00076 
00077 boolean mousedoubleclick (Point pt) {
00078 
00079     /*
00080     using the globals mouseuptime and mouseuppoint determine if a
00081     mouseclick at pt, right now, is a double click.
00082     
00083     dmb 9/6/90:  pt parameter is no longer used.  superceeded by new 
00084     mousedown globals
00085     */
00086     
00087     #pragma unused (pt)
00088     
00089     boolean fldoubleclick;
00090     short diff;
00091     
00092     fldoubleclick = (mousestatus.mousedowntime - mousestatus.mouseuptime) < GetDblTime ();
00093     
00094     if (fldoubleclick) { /*qualifies so far*/
00095         
00096         diff = pointdist (mousestatus.mousedownpoint, mousestatus.mouseuppoint);
00097         
00098         fldoubleclick = diff < 5; /*keep it set if mouse hasn't wandered too far*/
00099         }
00100     
00101     if (fldoubleclick) { /*user must doubleclick again to get effect*/
00102         
00103         mousestatus.mouseuptime = 0L;
00104         
00105         mousestatus.mouseuppoint.h = mousestatus.mouseuppoint.v = 0;
00106         }
00107     
00108     mousestatus.fldoubleclickdisabled = fldoubleclick; /*copy into global*/
00109     
00110     return (fldoubleclick);
00111     } /*mousedoubleclick*/
00112 
00113 
00114 boolean mousecheckautoscroll (Point pt, Rect r, boolean flhoriz, tydirection *dir) {
00115     
00116     /*
00117     if the point pt is outside of the rect r in the indicated dimension (flhoriz), 
00118     return true and set dir to the corresponding scroll direction.
00119     */
00120     
00121     tydirection d = nodirection;
00122     
00123     if (flhoriz) {
00124     
00125         if (pt.h < r.left)
00126             d = right;
00127         
00128         else if (pt.h > r.right)
00129             d = left;
00130         }
00131     else {
00132         
00133         if (pt.v < r.top)
00134             d = down;
00135         
00136         else if (pt.v > r.bottom)
00137             d = up;
00138         }
00139     
00140     *dir = d;
00141     
00142     return (d != nodirection);
00143     } /*mousecheckautoscroll*/
00144 
00145 

Generated on Wed May 31 18:19:43 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6