[comp.sys.mac.programmer] How do you find a window's location?

mjm@eleazar.dartmouth.edu (Michael McClennen) (05/29/90)

jwwalker@usceast.UUCP (Jim Walker) writes:

>I know how to set a window's location with MoveWindow and
>SizeWindow, but how do you *find* a window's location?  If the
>window is visible, I can use
>  (**((WindowPeek)window_ptr)->contRgn).rgnBBox
>but that seems to contain garbage when the window is invisible.
>Yet the Window Manager somehow keeps track of the locations of
>invisible windows.

How about checking the grafPort's portRect?

Michael McClennen
Dartmout College Academic Computing

wdh@well.sf.ca.us (Bill Hofmann) (05/31/90)

In article <22352@dartvax.Dartmouth.EDU> mjm@eleazar.dartmouth.edu (Michael McClennen) writes:
>jwwalker@usceast.UUCP (Jim Walker) writes:
>>I know how to set a window's location with MoveWindow and
>>SizeWindow, but how do you *find* a window's location?  If the
>>window is visible, I can use
>>  (**((WindowPeek)window_ptr)->contRgn).rgnBBox
>>but that seems to contain garbage when the window is invisible.
>>Yet the Window Manager somehow keeps track of the locations of
>>invisible windows.
>How about checking the grafPort's portRect?

The portRect of a grafPort is the top,left,bottom,right of the window in
LOCAL coordinates, that is, the coordinate system of the window.  (Note
that the top,left need not be 0,0).  What you want is the position of the
top,left in GLOBAL coordinates.  So, looking at Inside Mac Vol I-193:
	Point getWindowLocation(WindowPtr wp)
	{
		Point	where;
		GrafPtr	curPort;

		where.v = wp->portRect.top;
		where.h = wp->portRect.left;
		GetPort(&curPort);
		SetPort(wp);
		GlobalToLocal(&where);
		SetPort(curPort);
		return(where);
	}
If you want to include the title bar, which is above and to the left of
the content, you'll have to look at the strucRgn of the window.
-Bill Hofmann

wdh@well.sf.ca.us (Bill Hofmann) (05/31/90)

Oops, GlobalToLocal should be LocalToGlobal().  Geez, I've *never* made
*that* mistake before. 8->

-Bill

amanda@mermaid.intercon.com (Amanda Walker) (05/31/90)

> jwwalker@usceast.UUCP (Jim Walker) writes:
> >how do you *find* a window's location?

In article <22352@dartvax.Dartmouth.EDU>, mjm@eleazar.dartmouth.edu (Michael
McClennen) writes:
> How about checking the grafPort's portRect?

The portRect is in local coordinates.  What I do is SetPort to the Window,
make a copy of the portRect, and call LocalToGlobal on the corners.  If you
really want to be studly, you should also save & restore the zoomed state...

--
Amanda Walker
InterCon Systems Corporation