Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Saving window position question Message-ID: <7913@hoptoad.uucp> Date: 9 Jul 89 20:47:28 GMT References: <505@suna.CMI.COM> <7889@hoptoad.uucp> <12616@well.UUCP> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Distribution: usa Organization: Eclectic Software, San Francisco Lines: 55 In article <12616@well.UUCP> wdh@well.UUCP (Bill Hofmann) writes: >It's actually much easier than that: >{ > Rect saveWindow; > SetPort(myWindow); > saveWindow = myWindow->portRect; > LocalToGlobal(&(((Point *) &saveWindow)[0])); > LocalToGlobal(&(((Point *) &saveWindow)[1])); >} >Which does a LocalToGlobal on the topLeft and the botRight of the portRect. Not to put too fine a point on it, but that is easy only from the perspective of the software writer, not of the poor schlub who has to maintain the thing. Yes, I and many others are well aware that rectangles are laid out as two points; if I recall correctly, the standard Pascal definition is a variant record which lets one see either four integers or two points. However, this kind of typecasting and simulation of Pascal variants in C is at best idiosyncratic, and at word deliberately obscure for purposes of self-congratulation. It is, in brief, not clearly written. Much the same could be accomplished this way -- Point topLeft, bottomRight; Rect saveRect; SetPort(window); SetPt(&topLeft, window->portRect.left, window->portRect.top); SetPt(&bottomRight, window->portRect.right, window->portRect.bottom); LocalToGlobal(&topLeft); LocalToGlobal(&bottomRight); SetRect(&saveRect, topLeft.left, topLeft.top, bottomRight.right, bottomRight.bottom); Which I think is considerably more maintainable. It is slightly less computationally efficient, but then this is not a frequently performed operation, and my version still executes in far less time than it takes a human being to perceive an event. >Actually, what you probably *should* do is save the userState and stdState >of the window (assuming it's a zooming window). You can get those from the >dataHandle in the WindowRecord, and they're already global. Then, save >a boolean which tells you which state it's in (compare the globalized portRect >with one of them). Of course, when you open the document, you need to >check that the current state is on one of the current screens. Very good point. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com Postal: 424 Tehama, SF CA 94103; Phone: (415) 495-2934 "Yet another piece of evidence that it's a Communist society which is being presented as good, but which we probably would not want to live in." -- Ken Arromdee on rec.arts.startrek, on the Federation's Red Menace