From: keith@taligent.com (Keith Rollin)
Subject: Re: Q: GrayRgn + Menu bar region
Organization: Taligent
Date: Sun, 6 Sep 1992 23:44:43 GMT

In article <18dq7eINN48i@stanley.cis.Brown.EDU>, Andrew Gilmartin
<Andrew_Gilmartin@Brown.Edu> writes:
> 
> With WaitNextEvent() you can specify when to receive mouse
> moved messages by specifying a region within which you don't
> care about the mouse's movement but outside of which you do.
> When the mouse is outside of the front window, I only care to
> be notified when the mouse moves into the front window. This is
> simply done using a region that is the difference between the
> desktop and my window, for example
> 
> 		RectRgn( theWindowRgn, &theWindowRect );
> 		XorRgn( GetGrayRgn(), theWindowRgn, theCursorRgn );
> 
> The problem is that GetGrayRgn() excludes the menu bar and so I
> get mouse moved messages when the mouse moves there. Is there a
> clean way to get the full screen region (desktop and menu bar)?
> Thanks.

You don't need to be so selective. Instead of using GetGrayRgn(), create a
wide-open region from -32000 to 32000 in both directions, and subtract the
theWindowRgn from that. This technique will only cause problems if you move the
mouse off of the desktop, which you can't, so it won't, so there.

Here's how TESample on ftp.apple.com does it:

/*	Change the cursor's shape, depending on its position. This also calculates
the region
	where the current cursor resides (for WaitNextEvent). When the mouse moves
outside of
	this region, an event is generated. If there is more to the event than just
	the mouse moved, we get called before the event is processed to make sure
	the cursor is the right one. In any (ahem) event, this is called again before
we
	fall back into WNE. */

#pragma segment Main
void AdjustCursor(mouse,region)
	Point		mouse;
	RgnHandle	region;
{
	WindowPtr	window;
	RgnHandle	arrowRgn;
	RgnHandle	iBeamRgn;
	Rect		iBeamRect;

	window = FrontWindow();	/* we only adjust the cursor when we are in front */
	if ( (! gInBackground) && (! IsDAWindow(window)) ) {
		/* calculate regions for different cursor shapes */
		arrowRgn = NewRgn();
		iBeamRgn = NewRgn();

		/* start arrowRgn wide open */
		SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);

		/* calculate iBeamRgn */
		if ( IsAppWindow(window) ) {
			iBeamRect = (*((DocumentPeek) window)->docTE)->viewRect;
			SetPort(window);	/* make a global version of the viewRect */
			LocalToGlobal(&TopLeft(iBeamRect));
			LocalToGlobal(&BotRight(iBeamRect));
			RectRgn(iBeamRgn, &iBeamRect);
			/* we temporarily change the ports origin to globalfy the visRgn */
			SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
			SectRgn(iBeamRgn, window->visRgn, iBeamRgn);
			SetOrigin(0, 0);
		}

		/* subtract other regions from arrowRgn */
		DiffRgn(arrowRgn, iBeamRgn, arrowRgn);

		/* change the cursor and the region parameter */
		if ( PtInRgn(mouse, iBeamRgn) ) {
			SetCursor(*GetCursor(iBeamCursor));
			CopyRgn(iBeamRgn, region);
		} else {
			SetCursor(&qd.arrow);
			CopyRgn(arrowRgn, region);
		}

		DisposeRgn(arrowRgn);
		DisposeRgn(iBeamRgn);
	}
} /*AdjustCursor*/


--
Keith Rollin
Phantom Programmer
Taligent, Inc.

Newsgroups: comp.sys.mac.programmer