TEditSplitImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 3, 1985 6:14:10 pm PST
Russ Atkinson (RRA) June 25, 1985 2:36:01 am PDT
DIRECTORY
TEditDisplay USING [EstablishLine],
TEditDocument USING [LineTable, Selection, SelectionRec, SpinAndLock, TEditDocumentData, Unlock],
TEditOps USING [CopyLoadHistory, CopyPositionHistory],
TEditSplit USING [],
TextNode USING [Location],
ViewerClasses USING [Viewer],
ViewerLocks USING [CallUnderWriteLocks],
ViewerForkers USING [ForkPaint],
ViewerOps USING [AddProp, ComputeColumn, CreateViewer, DestroyViewer, FetchProp, MoveBelowViewer, OpenIcon, SetMenu];
TEditSplitImpl: CEDAR PROGRAM
IMPORTS TEditDisplay, TEditDocument, TEditOps, ViewerForkers, ViewerLocks, ViewerOps
EXPORTS TEditSplit
SHARES ViewerClasses
= BEGIN
Viewer: TYPE = ViewerClasses.Viewer;
Split: PUBLIC PROC [old: Viewer] = {
tddNew, tddOld: TEditDocument.TEditDocumentData;
new: Viewer;
paintCaption: BOOLFALSE;
selectionHistory: TEditDocument.Selection;
lines: TEditDocument.LineTable;
loc: TextNode.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. [McGregor]
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
{
inner: PROC = {
[] ← TEditDocument.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: TEditDocument.Selection ← NEW[TEditDocument.SelectionRec];
newSelectionHistory^ ← selectionHistory^;
ViewerOps.AddProp[new, $SelectionHistory, newSelectionHistory];
};
TEditOps.CopyPositionHistory[from: old, to: new];
TEditOps.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;
TEditDocument.Unlock[tddOld];
};
ViewerLocks.CallUnderWriteLocks[inner, old, new];
Must lock the viewers BEFORE trying for the document lock
};
TEditDisplay.EstablishLine[tddNew, loc];
ViewerOps.ComputeColumn[column: new.column, paint: TRUE]; -- now do the painting
FOR v: Viewer ← new.link, v.link WHILE v # NIL DO
IF v = new THEN EXIT;
IF v.iconic THEN { -- get rid of it -- ViewerOps.DestroyViewer[v]; EXIT };
IF paintCaption THEN
turn on [Split]
ViewerForkers.ForkPaint[viewer: v, hint: caption, tryShortCuts: TRUE];
ENDLOOP;
};
END.