SilDisplayImplA.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by: Ken Pier, August 15, 1986 9:34:05 am PDT
This module was created when SilDisplayImpl got too big for the compiler.
DIRECTORY
Abutters USING
[Abutter, Create, QuaViewer, SetLayout ],
BiScrollers USING [ClientDataOf, bsMenu, QuaBiScroller, QuaViewer],
Convert USING
[RopeFromInt, RopeFromCard],
Icons USING
[NewIconFromFile, IconFlavor],
Imager USING
[Context, Scale2T, SetPriorityImportant, VEC],
Menus USING
[CopyMenu],
MessageWindow USING
[Append, Blink],
Real USING
[RoundI],
RefText USING
[New],
Rope USING
[Cat, Equal, FromRefText ],
SystemVersion USING
[release],
UserProfile USING
[Boolean, Token],
ViewerClasses USING
[PaintProc, SaveProc, Viewer],
ViewerOps USING
[ComputeColumn, ViewerColumn],
ViewRec USING
[BindAllOfATypeFromTVs, RecognizeBoolShort, RecordViewer, RVQuaViewer, Viewer, ViewRef],
SilBiScrollers,
SilColor,
SilCommand,
SilDisplay,
SilDisplayCursors,
SilDisplayInternal,
SilDisplayPrivate,
SilDisplayUtils,
SilFile,
SilKernel,
SilUserInput
;
SilDisplayImplA: CEDAR MONITOR LOCKS dData USING dData: SilDisplayData
IMPORTS Abutters, BiScrollers, Convert, Icons, Imager, Menus, MessageWindow, Real, RefText, Rope, SilBiScrollers, --SilColor,-- SilDisplay, SilDisplayCursors, SilDisplayUtils, SilDisplayPrivate, SilFile, SilKernel, SilUserInput, SystemVersion, UserProfile, ViewerOps, ViewRec
EXPORTS SilDisplay, SilKernel = BEGIN OPEN SilFile;
SilData: TYPE = SilKernel.SilData;
SilModel: TYPE = SilFile.SilModel;
SilUIData: TYPE = SilKernel.SilUIData;
SilDisplayData: TYPE = REF SilDisplayDataRec;
SilDisplayDataRec: PUBLIC TYPE = SilDisplayInternal.SilDisplayDataRec;
UInputRec: TYPE = SilUserInput.UInputRec;
iconClean, iconDirty: Icons.IconFlavor ← document;
InitSil: PUBLIC PROC [] = {
Initialize Font, Caret, and display icon behavior.
defaultIconFile: ROPE ← Rope.Cat["/Cedar/CedarChest", Convert.RopeFromCard[from: SystemVersion.release.major, showRadix: FALSE], ".", Convert.RopeFromCard[from: SystemVersion.release.minor, showRadix: FALSE], "/Sil/Sil.icons"];
iconFile: ROPE ← UserProfile.Token[key: "Sil.IconFile", default: defaultIconFile];
iconClean ← Icons.NewIconFromFile[iconFile, 0];
iconDirty ← Icons.NewIconFromFile[iconFile, 1];
SilDisplayCursors.SilCursorsInit[];
SilDisplayUtils.SilUtilsInit[];
};
CaretBlink: PUBLIC PROC [] = {
Make sure that all the appropriate Sil Instances know to blink their carets.
SilDisplayCursors.SilCursorsBlink[];
};
GetIcon: PUBLIC PROC [dirtyIcon: BOOLFALSE] RETURNS [Icons.IconFlavor] ~ {
RETURN[IF dirtyIcon THEN iconDirty ELSE iconClean];
};
NeedRebuild: PUBLIC PROC [displayData: SilDisplayData] RETURNS [rebuild: BOOL] = {
TRUE if the display should be rebuilt.
RETURN[displayData.needRebuild];
};
CancelRebuild: PUBLIC PROC [displayData: SilDisplayData] = {
Called if the viewer has gone iconic; forget rebuilding
displayData.needRebuild ← displayData.inRebuild ← FALSE;
};
SilSaveProc: PUBLIC ViewerClasses.SaveProc = {
[self: Viewer, force: BOOLFALSE]
Save the contents of the viewer.
data: SilKernel.SilData ← NARROW[BiScrollers.QuaBiScroller[self].ClientDataOf[]];
dData: SilDisplayData ← data.displayData;
uiData: SilUIData ← data.uiData;
IF force THEN {
dData.largeFormat ← TRUE; --try not to lose anything in the drawing
dData.clipOutputFile ← FALSE;
SilDisplayUtils.OutputNamedFile[data, SilUserInput.GetBiScroller[uiData].QuaViewer[].parent.name, self]
}
ELSE SilDisplayUtils.OutputNamedFile[data, Rope.FromRefText[dData.collectingFileName], self];
};
SilPaintProc: PUBLIC ViewerClasses.PaintProc = {
[self: Viewer, context: Imager.Context, whatChanged: REF, clear: BOOL]
data: SilKernel.SilData ← NARROW[BiScrollers.QuaBiScroller[self].ClientDataOf[]];
dData: SilDisplayData ← data.displayData;
SilEntryPaintProc[dData, data, self, context, whatChanged];
};
SilEntryPaintProc: ENTRY PROC [dData: SilDisplayData, data: SilData, viewer: ViewerClasses.Viewer, context: Imager.Context, whatChanged: REF] = {
ctx: Imager.Context ← context;
Imager.Scale2T[ctx, [1.0, -1.0]];
Imager.SetPriorityImportant[ctx, TRUE];
IF dData.magnificationOn THEN SilDisplayUtils.ModifyContext[magnified, dData, ctx];
SELECT whatChanged FROM
The first 3 choices were supplied by Sil, and mean that the paint request originated in Sil, and the last two are originated by the Window Manager.
$UserInput => SilDisplay.SilUIPaint[data, viewer, ctx]; --called because of input
$Carets => SilDisplayCursors.SilCaretPaint[data, ctx]; --carets blink now
$Rebuild => SilDisplayUtils.SilRebuild[data, ctx]; --screen needs repair
NIL => { --screen needs full paint
boxXmin, boxYmin, boxXmax, boxYmax: INTEGER;
[boxXmin, boxYmin, boxXmax, boxYmax] ← SilDisplayUtils.BoundingBoxOfContext [ctx];
SilDisplayUtils.MergeRebuild[dData, data.model, boxXmin, boxYmin, boxXmax, boxYmax];
SilDisplayUtils.SilRebuild[data, ctx]
};
ENDCASE => ERROR; --This can't happen unless the world is really screwed
};
InitSilDisplayInstance: PUBLIC PROC [data: SilKernel.SilData, name: ROPENIL, instance: NAT] RETURNS [viewer: ViewerClasses.Viewer] = {
Get the display on the screen. Also, Initialize the text that will be used for rope input later.
cl: SilCommand.CommandRef;
dData: SilDisplayData ← NEW[SilDisplayDataRec]; --fills in default values from def
dData.commandLine ← NEW[SilCommand.CommandRec]; --this record to be ViewRefed
cl ← NARROW[dData.commandLine];
cl.Color ← SilColor.defaultColorChar; --other defaults done via initialization
data.model ← SilFile.NewSilModel[];
IF NOT Rope.Equal[name, ""] THEN {
name ← SilDisplayUtils.CheckFileExtension[name, input];
SilFile.MainFileToModel[data.model, name, FALSE ! SilKernel.SilError => {
MessageWindow.Append[name, TRUE];
MessageWindow.Append[" not found.", FALSE];
MessageWindow.Blink[];
REJECT};];
}
ELSE name ← Rope.Cat["SilNoName", Convert.RopeFromInt[from: instance, showRadix: FALSE]];
dData.collectingText ← RefText.New[SilFile.maxRopeLen];
dData.collectingFileName ←RefText.New[SilFile.maxRopeLen];
dData.oldText ← "";
dData.currentFontRef ← SilDisplayUtils.GetFont[
SilFile.InternalFontFromUserFont[dData.currentFont, dData.currentBoldState],
dData.currentItalicState
];
data.displayData ← dData;
{ --this block of code creates abutter, viewrec for the command data, and Sil BiScroller
vW: INTEGER = 600; --initial viewer width
vH: INTEGER = 17; --initial viewer height
bsH: INTEGER = 999;
abutter: Abutters.Abutter ← Abutters.Create[--saveChildren: TRUE,-- viewerFlavor: NIL, info: [name: name, menu: Menus.CopyMenu[BiScrollers.bsMenu], icon: iconClean, iconic: UserProfile.Boolean[key: "Sil.OpenIconic", default: FALSE], column: left, scrollable: FALSE], paint: FALSE];
outerViewer: ViewRec.Viewer ← Abutters.QuaViewer[abutter];
viewRec: ViewRec.RecordViewer ← ViewRec.ViewRef[agg: dData.commandLine, viewerInit: [parent: outerViewer, wx: 0, wy: 0, ww: vW, wh: vH], sample: FALSE, createOptions: [vSep: 1, hSep: 1, vPad: 1, hPad: 1, nvSep: 1, feedBackHeight: 0], specs: ViewRec.BindAllOfATypeFromTVs[aggType: CODE[SilCommand.CommandRec], eltType: CODE[BOOL], b: [name: NIL, it: TryRecognizer[ViewRec.RecognizeBoolShort]]], paint: FALSE];
viewRecViewer: ViewRec.Viewer ← ViewRec.RVQuaViewer[viewRec];
dData.viewRec ← viewRec; -- remember ViewRec for program controlled updating
viewer ← SilBiScrollers.bsStyle.CreateBiScroller[
class: SilBiScrollers.silClass,
info: [
column: left,
iconic: FALSE,
scrollable: TRUE,
wx: 0, wy: vH,
ww: vW, wh: bsH, --nominal values changed by Abutters.SetLayout
parent: outerViewer,
menu: NIL,
data: data],
paint: FALSE].QuaViewer[]; --this is the outer, containing abutter
SilUserInput.InitUserInput[data, viewer]; --must be called before painting
Abutters.SetLayout[ --see AbuttersTest.mesa.Test2 for explanation of this call !!
a: abutter,
rules: [
left: [NIL, none[]],
right: [NIL, parallel[LIST[
[NIL, stretch[[viewRecViewer]]],
[NIL, stretch[[viewer]]]
]]],
top: [LIST[[viewRecViewer]], stretch[[viewer]]],
bottom: [NIL, stretch[[viewer]]]
],
paint: FALSE];
Finally, we paint the new viewer and all the others it might affect.
ViewerOps.ComputeColumn[column: ViewerOps.ViewerColumn[outerViewer], paint: TRUE];
};
SilDisplayCursors.AquireAndDisableTheMark[data];
SilDisplayCursors.AquireAndDisableTheOrigin[data];
};
SilUIPaint: PUBLIC PROC [data: SilKernel.SilData, viewer: ViewerClasses.Viewer, ctx: Imager.Context] = {
Process the user inputs: reflect any changes in the model, and on the screen. If any rebuilds are necessary, set the appropriate values in dData.
TransformInputRec: PROC [args: UInputRec, dData: SilDisplayData, ctx: Imager.Context] RETURNS [UInputRec] = {
Make sure that any points in the record are transformed to reflect the correct coordinate system (could be in magnify mode).
point: Imager.VEC ← [0.0, 0.0]; --RECORD [x, y: REAL]
x, y: REAL;
TRUSTED { WITH temp: args SELECT FROM
SetCaret   => {point.x ← temp.x; point.y ← temp.y;};
SelectWithPos  => {point.x ← temp.x; point.y ← temp.y;};
OperateOnSelected  => {point.x ← temp.x; point.y ← temp.y;};
DrawBox   => {point.x ← temp.x; point.y ← temp.y;};
TrackMouse   => {point.x ← temp.x; point.y ← temp.y;};
ENDCASE;
};
Sil coordinates = (ClientCoords/scale) - offset
xScale = gridMagnification,
yScale = - gridMagnification,
IF dData.magnificationOn AND dData.currentMagnification#1 THEN {
point.x ← point.x/dData.currentMagnification;
point.y ← point.y/dData.currentMagnification;
};
x ← point.x - dData.xOffset;
y ← (-point.y) - dData.yOffset;
TRUSTED { WITH temp: args SELECT FROM
SetCaret => {temp.x ← Real.RoundI[x]; temp.y ← Real.RoundI[y];};
SelectWithPos => {temp.x ← Real.RoundI[x]; temp.y ← Real.RoundI[y];};
OperateOnSelected => {temp.x ← Real.RoundI[x]; temp.y ← Real.RoundI[y];};
DrawBox => {temp.x ← Real.RoundI[x]; temp.y ← Real.RoundI[y];};
TrackMouse => {temp.x ← Real.RoundI[x]; temp.y ← Real.RoundI[y];};
ENDCASE;
};
RETURN [args];
};
dData: SilDisplayData ← data.displayData;
WHILE SilUserInput.InputAvailable[data.uiData] DO
UI: UInputRec ← TransformInputRec[SilUserInput.Deque[data.uiData], dData, ctx];
WITH UI SELECT FROM
in: UInputRec.CenterOnMark => SilDisplayPrivate.CenterOnMark[in, data, viewer, ctx];
in: UInputRec.InputFile => SilDisplayPrivate.InputFile[in, data, viewer, ctx];
in: UInputRec.StoreFile => SilDisplayPrivate.StoreFile[in, data, viewer, ctx];
in: UInputRec.KillPicture => SilDisplayPrivate.KillPicture[in, data, viewer, ctx];
in: UInputRec.HardCopy => SilDisplayPrivate.HardCopy[in, data, viewer, ctx];
in: UInputRec.TrackMouse => SilDisplayPrivate.TrackMouse[in, data, viewer, ctx];
in: UInputRec.SetCaret => SilDisplayPrivate.SetCaret[in, data, viewer, ctx];
in: UInputRec.SetCursor => SilDisplayPrivate.SetCursor[in, data, viewer, ctx];
in: UInputRec.SelectWithPos => SilDisplayPrivate.SelectWithPos[in, data, viewer, ctx];
in: UInputRec.SelectForAttrib => SilDisplayPrivate.SelectForAttrib[in, data, viewer, ctx];
in: UInputRec.OperateOnSelected => SilDisplayPrivate.OperateOnSelected[in, data, viewer, ctx];
in: UInputRec.ChangeSelected => SilDisplayPrivate.ChangeSelected[in, data, viewer, ctx];
in: UInputRec.SetDefaultAttribs => SilDisplayPrivate.SetDefaultAttribs[in, data, viewer, ctx];
in: UInputRec.SetDetails => SilDisplayPrivate.SetDetails[in, data, viewer, ctx];
in: UInputRec.ManipulateMacro => SilDisplayPrivate.ManipulateMacro[in, data, viewer, ctx];
in: UInputRec.DrawBox => SilDisplayPrivate.DrawBox[in, data, viewer, ctx];
in: UInputRec.UserChar => SilDisplayPrivate.HandleInputChars[in, data, viewer, ctx];
in: UInputRec.Compliment => SilDisplayPrivate.Compliment[in, data, viewer, ctx];
in: UInputRec.ShowMacros => SilDisplayPrivate.ShowMacros[in, data, viewer, ctx];
in: UInputRec.SwapFonts => SilDisplayPrivate.SwapFonts[in, data, viewer, ctx];
in: UInputRec.Undelete => SilDisplayPrivate.Undelete[in, data, viewer, ctx];
in: UInputRec.MarkAsEdited => SilDisplayUtils.MarkFileAsEdited[data, ctx, viewer];
in: UInputRec.EraseArea => SilDisplayUtils.EraseArea[in.xMin, in.yMin, in.xMax, in.yMax, ctx];
in: UInputRec.MergeArea => SilDisplayUtils.MergeArea[dData, data.model, in.xMin, in.yMin, in.xMax, in.yMax, ctx];
ENDCASE => ERROR; --should be impossible
ENDLOOP;
};
END.