Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!apple!well!wdh From: wdh@well.UUCP (Bill Hofmann) Newsgroups: comp.sys.mac.programmer Subject: Re: WaitNextEvent Message-ID: <12992@well.UUCP> Date: 3 Aug 89 17:13:44 GMT References: <11875@orstcs.CS.ORST.EDU> <227700022@uxa.cso.uiuc.edu> <8211@hoptoad.uucp> Reply-To: wdh@well.UUCP (Bill Hofmann) Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 68 In article <8211@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes: >Does anyone have any example code which illustrates the use of the >mouse region argument to WaitNextEvent? /* return a region handle which is either the content of the * window passed (we assume it's the active one) or everything * but. If the mouse is inside the window, set the cursor to * a plus cursor, otherwise, reset to arrow */ RgnHandle AdjustMaus(wp) WindowPeek wp; { RgnHandle mausRgn; Point mausLoc; Rect windowRect; if (mausRgn = NewRgn()) { GetMouse(&mausLoc); LocalToGlobal(&mausLoc); /* use the content region of the window: it's * almost what we want, in global coordinates. * To be absolutely correct, we should use the * visRgn, which is in coordinate local to wp, * but represents what is *actually* visible, but * then we'd have to LocalToGlobal it, and * I'm too lazy just now. */ CopyRgn(wp->contRgn,mausRgn); if (PtInRgn(mausLoc,mausRgn)) SetCursor(*GetCursor(plusCursor)); else { RgnHandle temp = NewRgn(); CopyRgn(GetGrayRgn(),mausRgn); RectRgn(temp,&screenBits.bounds); UnionRgn(mausRgn,temp,mausRgn); DisposeRgn(temp); /* now mausRgn is the *whole* screen, including * the menu bar */ DiffRgn(mausRgn,wp->contRgn,mausRgn); /* Now, mausRgn is everything *BUT* the content * of the window. */ InitCursor(); } } return(mausRgn); } The return value of this routine can be passed to WaitNextEvent(), which will notify us if the mouse leaves the region with a mouseMoved app4Evt. In my real code, I use visRgn and mausRgn is a global, so I don't have to keep disposing the region before I call this routine (and I don't alloc a new region every time). But this'll give you the idea. -Bill Hofmann >-- >Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com > >"As I was walking among the fires of Hell, delighted with the enjoyments of > Genius; which to Angels look like torment and insanity. I collected some of > their Proverbs..." - Blake, "The Marriage of Heaven and Hell" "Sacred cows make the tastiest hamburger" -Abbie Hoffman