SCRowUtilImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
row utility routines
DIRECTORY
Rope, RTSets, SC, SCInstUtil, SCPrivate, SCRowUtil;
SCRowUtilImpl: CEDAR PROGRAM
IMPORTS RTSets, SC, SCInstUtil, SCRowUtil
EXPORTS SCRowUtil
SHARES SC = BEGIN
sideName: PUBLIC ARRAY SC.SideOrNone OF Rope.ROPE ← ["bottom", "top", "left", "right", "none"];
find the max row length
FindMaxRow: PUBLIC PROCEDURE [handle: SC.Handle] RETURNS [
maxRowWidth : SC.Number ← 0, numMaxRows : SCPrivate.ZMaxRowSr ← 0] = {
RowProc: SCRowUtil.EachRowProc = {
IF lgRow.size.p > maxRowWidth THEN
{maxRowWidth ← lgRow.size.p; numMaxRows ← 1}
ELSE IF lgRow.size.p = maxRowWidth THEN
numMaxRows ← numMaxRows + 1};
[] ← SCRowUtil.EnumerateRows[handle, RowProc]};
audit the row lengths
AuditRowLengths: PUBLIC PROCEDURE [handle: SC.Handle] = {
RowProc: SCRowUtil.EachRowProc = {
InstProc: SCRowUtil.EachInstProc = {
SELECT instance.whichClass FROM
ft => NULL;
logic => {
instance.offset ← offset;
offset ← offset + SCInstUtil.InstWidth[instance]};
ENDCASE =>
SC.Error[programmingError, "Invalid Instance on Row"]};
offset: INT ← lgRow.nFtsOnRow*ftObject.size.p;
[] ← SCRowUtil.EnumerateAllInstsOnRow[handle, row, InstProc];
IF offset # lgRow.size.p THEN SC.Error[programmingError, "Invalid row length"]};
parms: SCPrivate.Parms ← NARROW[handle.parms];
ftObject: SCPrivate.Object ← parms.ftObject;
[] ← SCRowUtil.EnumerateRows[handle, RowProc]};
compute height of row - height is max of component heights on row
ComputeRowHeight: PUBLIC PROCEDURE[handle: SC.Handle, row: SCPrivate.MaxRowSr] = {
RowProc: SCRowUtil.EachInstProc = {
maxHeight ← MAX[maxHeight, SCInstUtil.InstHeight[instance]]};
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
lgRow: SCPrivate.LgRow ← layoutData.lgRows.rows[row];
maxHeight: SC.Number ← 0;
[] ← SCRowUtil.EnumerateAllInstsOnRow[handle, row, RowProc];
lgRow.size.q ← maxHeight;
lgRow.dimInvalid ← FALSE};
compute height of side - height is max of component heights on side
ComputeSideHeight: PUBLIC PROCEDURE[handle: SC.Handle, side: SC.Side] = {
SideProc: SCRowUtil.EachInstProc = {
maxHeight ← MAX[maxHeight, SCInstUtil.BpHeight[instance]]};
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
bpRow: SCPrivate.BpRow ← layoutData.bpRows[side];
maxHeight: SC.Number ← 0;
[] ← SCRowUtil.EnumerateAllInstsOnSide[handle, side, SideProc];
bpRow.size.q ← maxHeight;
bpRow.dimInvalid ← FALSE};
find rows that these comps are on
RowsForInsts: PUBLIC PROCEDURE[insts: SCPrivate.InstanceList]
RETURNS [
onSide: SCPrivate.SideSet ← RTSets.RTSmSetEmpty,
onRow: SCPrivate.RowSet ← RTSets.RTLgSetEmpty] = {
FOR instList: SCPrivate.InstanceList ← insts, instList.rest WHILE instList # NIL DO
inst: SCPrivate.Instance ← instList.first;
SELECT inst.whichClass FROM
ft, logic => {IF inst.curRow > 0 THEN
onRow ← RTSets.RTLgSetUnion[onRow, RTSets.RTLgSetGenerateElement[(inst.curRow)-1]]};
io => {IF inst.curSide # none THEN
onSide ← RTSets.RTSmSetUnion[onSide, RTSets.RTSmSetGenerateElement[LOOPHOLE[SC.Side[inst.curSide], INTEGER]]]};
ENDCASE;
ENDLOOP};
EnumerateRows: PUBLIC PROC [handle: SC.Handle, eachRow: SCRowUtil.EachRowProc] RETURNS [quit: BOOLFALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
lgRows: SCPrivate.LgRows ← layoutData.lgRows;
FOR row: SCPrivate.MaxRowSr IN [1 .. lgRows.count] WHILE ~quit DO
quit ← eachRow[row, lgRows.rows[row]];
ENDLOOP};
EnumerateSides: PUBLIC PROC [handle: SC.Handle, eachSide: SCRowUtil.EachSideProc] RETURNS [quit: BOOLFALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
bpRows: SCPrivate.BpRows ← layoutData.bpRows;
FOR side: SC.Side IN SC.Side WHILE ~quit DO
quit ← eachSide[side, bpRows[side]];
ENDLOOP};
EnumerateAllInstsOnRow: PUBLIC PROC [handle: SC.Handle, row: SCPrivate.MaxRowSr, eachInstance: SCRowUtil.EachInstProc] RETURNS [quit: BOOLFALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
lgRow: SCPrivate.LgRow ← layoutData.lgRows.rows[row];
quit ← SCRowUtil.EnumerateInstsOnRow[handle, row, 1, lgRow.nLgsOnRow, eachInstance]};
EnumerateInstsOnRow: PUBLIC PROC [handle: SC.Handle, row: SCPrivate.MaxRowSr, startPos, endPos: SCPrivate.ZMaxPosSr, eachInstance: SCRowUtil.EachInstProc] RETURNS [quit: BOOL ← FALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
lgRow: SCPrivate.LgRow ← layoutData.lgRows.rows[row];
FOR inst: NAT IN [startPos .. endPos] WHILE ~quit DO
quit ← eachInstance[inst, lgRow.lgsOnRow[inst]];
ENDLOOP};
EnumerateInstsOnRowDecreasing: PUBLIC PROC [handle: SC.Handle, row: SCPrivate.MaxRowSr, startPos, endPos: SCPrivate.ZMaxPosSr, eachInstance: SCRowUtil.EachInstProc] RETURNS [quit: BOOL ← FALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
lgRow: SCPrivate.LgRow ← layoutData.lgRows.rows[row];
FOR inst: NAT DECREASING IN [startPos .. endPos] WHILE ~quit DO
quit ← eachInstance[inst, lgRow.lgsOnRow[inst]];
ENDLOOP};
EnumerateAllInstsOnSide: PUBLIC PROC [handle: SC.Handle, side: SC.Side, eachInstance: SCRowUtil.EachInstProc] RETURNS [quit: BOOL ← FALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
bpRow: SCPrivate.BpRow ← layoutData.bpRows[side];
quit ← SCRowUtil.EnumerateInstsOnSide[handle, side, 1, bpRow.nBpsOnSide, eachInstance]};
EnumerateInstsOnSide: PUBLIC PROC [handle: SC.Handle, side: SC.Side, startPos, endPos: SCPrivate.ZMaxPosSr, eachInstance: SCRowUtil.EachInstProc] RETURNS [quit: BOOLFALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
bpRow: SCPrivate.BpRow ← layoutData.bpRows[side];
FOR inst: NAT IN [startPos .. endPos] WHILE ~quit DO
quit ← eachInstance[inst, bpRow.bpsOnSide[inst]];
ENDLOOP};
EnumerateInstsOnSideDecreasing: PUBLIC PROC [handle: SC.Handle, side: SC.Side, startPos, endPos: SCPrivate.ZMaxPosSr, eachInstance: SCRowUtil.EachInstProc] RETURNS [quit: BOOLFALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
bpRow: SCPrivate.BpRow ← layoutData.bpRows[side];
FOR inst: NAT DECREASING IN [startPos .. endPos] WHILE ~quit DO
quit ← eachInstance[inst, bpRow.bpsOnSide[inst]];
ENDLOOP};
END.