home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15060 < prev    next >
Encoding:
Text File  |  1992-09-08  |  3.4 KB  |  103 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!sun-barr!ames!data.nas.nasa.gov!taligent!keith@taligent.com
  3. From: keith@taligent.com (Keith Rollin)
  4. Subject: Re: Q: GrayRgn + Menu bar region
  5. Message-ID: <Bu6KMJ.4D2@taligent.com>
  6. Sender: usenet@taligent.com (More Bytes Than You Can Read)
  7. Organization: Taligent
  8. References: <18dq7eINN48i@stanley.cis.Brown.EDU>
  9. Date: Sun, 6 Sep 1992 23:44:43 GMT
  10. Lines: 91
  11.  
  12. In article <18dq7eINN48i@stanley.cis.Brown.EDU>, Andrew Gilmartin
  13. <Andrew_Gilmartin@Brown.Edu> writes:
  14. > With WaitNextEvent() you can specify when to receive mouse
  15. > moved messages by specifying a region within which you don't
  16. > care about the mouse's movement but outside of which you do.
  17. > When the mouse is outside of the front window, I only care to
  18. > be notified when the mouse moves into the front window. This is
  19. > simply done using a region that is the difference between the
  20. > desktop and my window, for example
  21. >         RectRgn( theWindowRgn, &theWindowRect );
  22. >         XorRgn( GetGrayRgn(), theWindowRgn, theCursorRgn );
  23. > The problem is that GetGrayRgn() excludes the menu bar and so I
  24. > get mouse moved messages when the mouse moves there. Is there a
  25. > clean way to get the full screen region (desktop and menu bar)?
  26. > Thanks.
  27.  
  28. You don't need to be so selective. Instead of using GetGrayRgn(), create a
  29. wide-open region from -32000 to 32000 in both directions, and subtract the
  30. theWindowRgn from that. This technique will only cause problems if you move the
  31. mouse off of the desktop, which you can't, so it won't, so there.
  32.  
  33. Here's how TESample on ftp.apple.com does it:
  34.  
  35. /*    Change the cursor's shape, depending on its position. This also calculates
  36. the region
  37.     where the current cursor resides (for WaitNextEvent). When the mouse moves
  38. outside of
  39.     this region, an event is generated. If there is more to the event than just
  40.     ╥the mouse moved╙, we get called before the event is processed to make sure
  41.     the cursor is the right one. In any (ahem) event, this is called again before
  42. we
  43.     fall back into WNE. */
  44.  
  45. #pragma segment Main
  46. void AdjustCursor(mouse,region)
  47.     Point        mouse;
  48.     RgnHandle    region;
  49. {
  50.     WindowPtr    window;
  51.     RgnHandle    arrowRgn;
  52.     RgnHandle    iBeamRgn;
  53.     Rect        iBeamRect;
  54.  
  55.     window = FrontWindow();    /* we only adjust the cursor when we are in front */
  56.     if ( (! gInBackground) && (! IsDAWindow(window)) ) {
  57.         /* calculate regions for different cursor shapes */
  58.         arrowRgn = NewRgn();
  59.         iBeamRgn = NewRgn();
  60.  
  61.         /* start arrowRgn wide open */
  62.         SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
  63.  
  64.         /* calculate iBeamRgn */
  65.         if ( IsAppWindow(window) ) {
  66.             iBeamRect = (*((DocumentPeek) window)->docTE)->viewRect;
  67.             SetPort(window);    /* make a global version of the viewRect */
  68.             LocalToGlobal(&TopLeft(iBeamRect));
  69.             LocalToGlobal(&BotRight(iBeamRect));
  70.             RectRgn(iBeamRgn, &iBeamRect);
  71.             /* we temporarily change the port╒s origin to ╥globalfy╙ the visRgn */
  72.             SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
  73.             SectRgn(iBeamRgn, window->visRgn, iBeamRgn);
  74.             SetOrigin(0, 0);
  75.         }
  76.  
  77.         /* subtract other regions from arrowRgn */
  78.         DiffRgn(arrowRgn, iBeamRgn, arrowRgn);
  79.  
  80.         /* change the cursor and the region parameter */
  81.         if ( PtInRgn(mouse, iBeamRgn) ) {
  82.             SetCursor(*GetCursor(iBeamCursor));
  83.             CopyRgn(iBeamRgn, region);
  84.         } else {
  85.             SetCursor(&qd.arrow);
  86.             CopyRgn(arrowRgn, region);
  87.         }
  88.  
  89.         DisposeRgn(arrowRgn);
  90.         DisposeRgn(iBeamRgn);
  91.     }
  92. } /*AdjustCursor*/
  93.  
  94.  
  95. --
  96. Keith Rollin
  97. Phantom Programmer
  98. Taligent, Inc.
  99.  
  100.