-- TiogaSplitImpl.mesa, Edited by Paxton on June 14, 1983 3:21 pm
-- Edited by McGregor on August 27, 1982 2:38 pm
DIRECTORY
TiogaDisplay USING [EstablishLine],
TiogaDocument USING [LineTable, Selection, SelectionRec, SpinAndLock, TiogaDocumentData, Unlock],
TiogaOps USING [CopyLoadHistory, CopyPositionHistory],
TiogaSplit,
TiogaNode USING [Location],
ViewerClasses USING [Viewer],
ViewerOps USING [AddProp, ComputeColumn, CreateViewer, DestroyViewer, FetchProp,
MoveBelowViewer, OpenIcon, PaintViewer, SetMenu];
TiogaSplitImpl: CEDAR PROGRAM
IMPORTS TiogaDisplay, TiogaDocument, TiogaOps, ViewerOps
EXPORTS TiogaSplit
SHARES ViewerClasses =
BEGIN OPEN ViewerClasses;
Split: PUBLIC PROC [old: Viewer] = BEGIN
tddNew, tddOld: TiogaDocument.TiogaDocumentData;
new: Viewer;
paintCaption: BOOLFALSE;
selectionHistory: TiogaDocument.Selection;
lines: TiogaDocument.LineTable;
loc: TiogaNode.Location;
tddOld ← NARROW[old.data];
IF tddOld = NIL THEN RETURN;
new ← ViewerOps.CreateViewer[flavor: old.class.flavor, info: [name: old.name,
column: old.column, iconic: TRUE], paint: FALSE];
ViewerOps.OpenIcon[icon: new, paint: FALSE];
ViewerOps.MoveBelowViewer[altered: new, static: old, paint: FALSE];
tddNew ← NARROW[new.data];
IF tddNew = NIL THEN RETURN; -- How this could happen is beyond me, but paranoia is cheap.
selectionHistory ← NARROW[ViewerOps.FetchProp[old, $SelectionHistory]];
new.link ← old;
IF old.link=NIL THEN { old.link ← new; paintCaption ← TRUE }
ELSE FOR v: Viewer ← old.link, v.link UNTIL v.link=old DO
REPEAT FINISHED => v.link ← new;
ENDLOOP;
new.newVersion ← old.newVersion;
new.newFile ← old.newFile;
new.file ← old.file;
ViewerOps.ComputeColumn[column: new.column, paint: FALSE]; -- to find new height
[] ← TiogaDocument.SpinAndLock[tddOld, "Split"]; -- must ComputeColumn before lock tdd
tddNew.text ← tddOld.text;
tddNew.tsInfo ← tddOld.tsInfo;
tddNew.clipLevel ← tddOld.clipLevel;
tddNew.commentFilter ← tddOld.commentFilter;
ViewerOps.SetMenu[new, old.menu, FALSE];
IF selectionHistory # NIL THEN { -- copy it
newSelectionHistory: TiogaDocument.Selection ← NEW[TiogaDocument.SelectionRec];
newSelectionHistory^ ← selectionHistory^;
ViewerOps.AddProp[new, $SelectionHistory, newSelectionHistory] };
TiogaOps.CopyPositionHistory[from: old, to: new];
TiogaOps.CopyLoadHistory[from: old, to: new];
lines ← tddOld.lineTable;
loc ← lines[lines.lastLine].pos; -- in case loop doesn't find anything
FOR n: INTEGER IN [0..lines.lastLine] DO -- find line that goes past new bottom
IF lines[n].yOffset+lines[n].descent >= old.ch THEN {
loc ← lines[n].pos; EXIT };
ENDLOOP;
TiogaDocument.Unlock[tddOld];
TiogaDisplay.EstablishLine[tddNew, loc];
ViewerOps.ComputeColumn[column: new.column, paint: TRUE]; -- now do the painting
FOR v: Viewer ← new.link, v.link UNTIL v=new DO
IF v.iconic THEN { -- get rid of it -- ViewerOps.DestroyViewer[v]; EXIT };
IF paintCaption THEN ViewerOps.PaintViewer[v, caption]; -- turn on [Split]
ENDLOOP;
END;
END.