[comp.sys.mac.programmer] "DeltaMoveWindow"?

nick@lfcs.ed.ac.uk (Nick Rothwell) (05/03/89)

I was rather surprised to find that the Window Manager doesn't have a
DeltaMoveWindow trap - there's only MoveWindow, which is absolute. I have
an application where each "document" (for want of a better word) appears
in a number of small windows with WIND templates held in a resource file.
If I'm opening several "documents" at once, I want the appearance of the
windows to be staggered slightly in a diagonal down the screen, so that
they're all visible. So, I had to hack up a "DeltaMoveWindow". This is what
I came up with - ugly, but it seems to work. If anybody has a nicer way of
doing this, I'd really like to know...!

	static void deltaMoveWindow(win, dx, dy)
	WindowPtr win;
	int dx, dy;
	{
		int oldX = -((WindowPeek) win)->port.portBits.bounds.left,
			oldY = -((WindowPeek) win)->port.portBits.bounds.top;

		MoveWindow(win, oldX + dx, oldY + dy, false);
	}

		Nick.
Nick Rothwell,	Laboratory for Foundations of Computer Science, Edinburgh.
		nick@lfcs.ed.ac.uk    <Atlantic Ocean>!mcvax!ukc!lfcs!nick
~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
               Fais que ton reve soit plus long que la nuit.

darin@Apple.COM (Darin Adler) (05/04/89)

In article <1908@etive.ed.ac.uk> nick@lfcs.ed.ac.uk (Nick Rothwell) writes:
> I was rather surprised to find that the Window Manager doesn't have a
> DeltaMoveWindow trap - there's only MoveWindow, which is absolute. I have
> an application where each "document" (for want of a better word) appears
> in a number of small windows with WIND templates held in a resource file.
> If I'm opening several "documents" at once, I want the appearance of the
> windows to be staggered slightly in a diagonal down the screen, so that
> they're all visible. So, I had to hack up a "DeltaMoveWindow". This is what
> I came up with - ugly, but it seems to work. If anybody has a nicer way of
> doing this, I'd really like to know...!

Here's a pretty good implementation:

void
DeltaMoveWindow(WindowPtr window, short hOffset, short vOffset, Boolean front)
	{
	GrafPtr	savedPort;		/* use to save the current grafport */
	Point	topLeft;		/* use to calculate global top-left */
	
	GetPort(&savedPort);
	SetPort(window);
	
	topLeft.v = window->portRect.top;
	topLeft.h = window->portRect.left;	
	LocalToGlobal(&topLeft);	/* convert to global coordinates */
	MoveWindow(window, topLeft.h + hOffset, topLeft.v + vOffset, front);

	SetPort(savedPort);
	}

I don't think you really need this routine to do what you described, though.
Most applications stagger the windows by changing the rectangle they appear in,
rather than repeatedly moving the window. Also, this will cause your windows to
stagger off the screen, unless you make a separate check.
-- 
Darin Adler, System Software Scapegoat, Apple Computer
	Internet: darin@Apple.com
	UUCP: {nsc,sun}!apple!darin

oster@dewey.soe.berkeley.edu (David Phillip Oster) (05/04/89)

In article <1908@etive.ed.ac.uk> nick@lfcs.ed.ac.uk (Nick Rothwell) writes:
_>I was rather surprised to find that the Window Manager doesn't have a
_>DeltaMoveWindow trap - there's only MoveWindow, which is absolute. 
_>This is what
_>I came up with - ugly, but it seems to work. If anybody has a nicer way of
_>doing this, I'd really like to know...!
The posted code doesn't handle the following issues:
1.) windows based on a color grafport
2.) attempts to move a window off of any CRT
3.) Windows where SetOrigin() has been used to make the origin not 0,0.

I am not sure that all of these are problems, but surely some of them
are.