/*
** SpreadViews.ced
**
** $VER: SpreadViews.ced 1.0.0 (2.6.93)
**
** This script will make each view on the display the same size (or as close
** to the same size as possible).
**
** This script requires CygnusEd Professional v3.5 (or later) to run.
**
** Copyright © 1990-1993 ASDG, Incorporated  All Rights Reserved
*/


OPTIONS RESULTS


/*
** Calculate the desired number of rows per view.
*/

STATUS WINDOWHEIGHT			/* Find out how high the entire CED window is. */
NumLines = (RESULT - 3) % 8		/* Three extra pixels in top title bar. */

STATUS TOTALNUMVIEWS			/* Find the number of views open. */
NumViews = RESULT
IF (NumViews = 1) THEN DO
	CEDTOFRONT
	OKAY1 'Only one view!'
	EXIT 10
END
Desire = NumLines % NumViews		/* Now that we know the total number of lines */
					/* and the total number of views, we can calculate */
					/* how large each view should be. */
Remainder = (NumLines - (Desire * NumViews))
Desire = Desire - 1			/* Ignore title lines. */
CurrView = 0				/* Store location of original view. */

/*
** Get to bottom view.
*/

STATUS PIXELTOPEDGE
MaxY = RESULT
NewRes = MaxY				/* Loop through all of the views, looking for the last one. */
DO UNTIL (MaxY > NewRes)
	MaxY = NewRes
	NEXT VIEW
	CurrView = CurrView + 1
	STATUS PIXELTOPEDGE
	NewRes = RESULT
END
PREVIOUS VIEW
CurrView = CurrView - 1

/*
** Size each view from the bottom up.
*/

DO WHILE (NumViews > 1)
	STATUS DISPLAYLINES
	OrigLines = RESULT
	Diff = OrigLines - Desire

	/*
	** Account for remainder if numbers aren't even.
	*/

	IF (Remainder > 0) THEN DO
		Diff = Diff - 1
		Remainder = Remainder - 1
	END

	/*
	** Size the window.
	*/

	DO WHILE (Diff < 0)		/* Make the window larger if necessary */
		GROW VIEW
		Diff = Diff + 1
	END
	DO WHILE (Diff > 0)		/* Make the window smaller if necessary */
		SHRINK VIEW
		Diff = Diff - 1
	END
	PREVIOUS VIEW
	CurrView = CurrView - 1
	NumViews = NumViews - 1
END

/*
** Return to original view.
*/

DO WHILE (CurrView < 0)
	NEXT VIEW
	CurrView = CurrView + 1
END

EXIT 0
