-- file: Editor.Mesa
-- last edited by Brotz, February 3, 1982 11:03 AM
-- last edited by Levin, February 21, 1980 3:44 PM
DIRECTORY
inD: FROM "InteractorDefs" USING [CharIndex, HousePtr, KeyboardInputAcceptor,
LinePtr, MessageTextNbrPtr, ScreenXCoord, ScreenYCoord, TextSelectionPtr],
KeyDefs USING [updown],
vmD: FROM "VirtualMgrDefs" USING [VirtualMessagePtr];
Editor: DEFINITIONS =
BEGIN
OPEN inD;
-- Editor Department of the Interactor Division
-- Implements the editor for the composed message. Commands are: Insert, Append,
-- Replace, Delete, Undo, Redo. Other operations (which are not commands per se) are
-- selection, scrolling, and command aborting.
EditorType: TYPE = {modal, modeless};
CommandType: TYPE = {noCommand, insert, delete, append, replace, get};
Rectangle: TYPE = RECORD
[left, right: ScreenXCoord,
top, bottom: ScreenYCoord];
UnderlineType: TYPE = {target, source};
UnrecognizedCommandProcedure: TYPE = PROCEDURE
[mnp: MessageTextNbrPtr, char: CHARACTER];
shiftedSelectionFlag: CHARACTER = 241C;
-- If in keystream, indicates use secondary selection.
nextCode: CHARACTER = 35C; -- NEXT key set to this value if editor is modeless.
cancelCode: CHARACTER = 36C; -- CANCEL key set to this value if editor is modeless.
insertDeletionCode: CHARACTER = 37C; -- LF key set to this value if editor is modeless.
nextBracketStringCode: CHARACTER = 242C; -- red bug of bracket command house.
composedMessagePages: CARDINAL = 5;
insertionBufferPages: CARDINAL = 2;
deletionBufferPages: CARDINAL = 2;
-- Procedures --
AcceptTypeIn: PROCEDURE [mnp: MessageTextNbrPtr, char: CHARACTER];
BracketCommand: PROCEDURE [mnp: MessageTextNbrPtr, char: CHARACTER];
ButlersBoundaryCommand: PROCEDURE [commandNumber: CARDINAL];
CancelSourceSelection: PROCEDURE [mnp: MessageTextNbrPtr];
CancelTargetSelection: PROCEDURE;
Decode: KeyboardInputAcceptor;
-- Dispatches to specific routines for handling a specific editor command. Fixes up
-- scratch buffer and lastCommand upon return of any of the command routines.
Deleter: PROCEDURE [mnp: MessageTextNbrPtr];
-- Deletes primary selection from mnp.message. Sets new primary selection to the null
-- range at the start of the just used primary selection. Depends on caller to adjust
-- primary selection after return if default selection is desired.
DoTargetSelection: PROCEDURE;
FCommand: PROCEDURE;
FindOperation: PROCEDURE [s: STRING, start, end: CharIndex,
message: vmD.VirtualMessagePtr]
RETURNS [found: BOOLEAN, at, atEnd, patternEnd: CharIndex];
-- Searches for a match to s within [start .. end) of mnp.message. If found, returns TRUE,
-- with [at .. atEnd) the matched range, and patternEnd the first character not matched
-- by the pattern, which may differ from atEnd due to } selection termination.
GCommand: PROCEDURE [mnp: MessageTextNbrPtr];
-- Replaces the current primary selection with the contents of the file named in
-- the get/put brackets.
Getter: PROCEDURE [start, end: CharIndex, mnp: MessageTextNbrPtr,
fileName: STRING];
-- Replaces [start .. end) from mnp.message with contents of fileName.
InsertFromLastCommand: PROCEDURE [mnp: MessageTextNbrPtr];
-- Only callable if editorType = modal. Implements R ESC, A ESC, I ESC.
InsertLastDeletion: PROCEDURE [mnp: MessageTextNbrPtr];
-- Only callable if editor is modeless. Implements the editor Move command.
MakeCharIndexVisible: PROCEDURE [index: CharIndex, mnp: MessageTextNbrPtr,
offScreenSlop: CARDINAL ← 40] RETURNS [line: LinePtr];
-- Ensures that the caret will be visible during type in.
PCommand: PROCEDURE [mnp: MessageTextNbrPtr];
-- Writes the current primary selection onto the file named in the get/put brackets.
PrepareForTypeIn: PROCEDURE [mnp: MessageTextNbrPtr];
-- Resets primary selection and handles pending delete properly.
Putter: PROCEDURE [start, end: CharIndex, mnp: MessageTextNbrPtr,
hp: HousePtr, oldText: STRING] RETURNS [successful: BOOLEAN];
-- Writes [start .. end) from mnp.message onto file named in hp.text.
Redo: PROCEDURE [mnp: MessageTextNbrPtr];
-- Redoes the last command with the Segment [start .. end).
SCommand: PROCEDURE;
SelectEverything: PROCEDURE [mnp: MessageTextNbrPtr];
-- Implements editor E command.
SelectNextBlank: PROCEDURE [mnp: MessageTextNbrPtr, forward: BOOLEAN ← TRUE];
-- Implements editor NEXT command.
TCommand: PROCEDURE [mnp: MessageTextNbrPtr];
TurnOnDeliver: PROCEDURE;
Undo: PROCEDURE [mnp: MessageTextNbrPtr];
-- Undoes the last command, ignoring subsequent window commands or selections.
UnrecognizedCommand: PROCEDURE;
UpdateScreen: PROCEDURE [start: CharIndex, nCharsDeleted,
nCharsInserted: CARDINAL, mnp: MessageTextNbrPtr,
select: BOOLEAN ← TRUE];
-- Shortcut call to screen refreshers. Updates selections and Deliver command as well.
-- Smart Display Section of the Editor Department
-- Maintains lines and characters within lines on the screen. Handles scrolling,
-- refreshing, mapping x,y to character indices.
RefreshFromFirstChange: PROCEDURE [actionIndex: CharIndex,
deletedChars, insertedChars: CARDINAL, mnp: MessageTextNbrPtr];
-- A change in the message text has occured at actionPoint. Its relation to the screen is
-- unknown. This routine is to fix up the screen to reflect the new state of the message
-- text.
RefreshToPlaceCharOnLine: PROCEDURE [startCharIndex: CharIndex, line: LinePtr,
mnp: MessageTextNbrPtr, underline: BOOLEAN ← TRUE];
-- Refresh CM window from line on (inclusive), so that firstCharIndex appears somewhere
-- in line after refresh. Selections will be refreshed with their underlines iff underline
-- is TRUE.
RefreshSoThatFirstCharStartsLine: PROCEDURE [firstChar: CharIndex,
firstLine: LinePtr, mnp: MessageTextNbrPtr, underline: BOOLEAN ← TRUE];
-- Refresh all lines of screen in range [firstLine .. bottomLine], so that firstChar starts
-- firstLine. Selections will be refreshed with their underlines iff underline is TRUE.
-- Side effects: advances highWaterMark.
RefreshEndOfMessage: PROCEDURE [mnp: MessageTextNbrPtr];
-- Repaints "End of Message" line if visible with current endOfMessageString.
MapXInLineToCharIndex: PROCEDURE [x: ScreenXCoord, line: LinePtr,
message: vmD.VirtualMessagePtr]
RETURNS [index: CharIndex, leftX, rightX: ScreenXCoord];
-- Returns the charIndex covering x in line and returns the x bounds of that charIndex.
MapYToNonBlankLine: PROCEDURE [y: ScreenYCoord, mnp: MessageTextNbrPtr]
RETURNS [line: LinePtr];
-- Returns the screen line associated with y. If y falls on blank line below the end of
-- message, then returns the end of message line.
ClearScreenLinesToTrailingBlankLines: PROCEDURE [startLine: LinePtr,
charIndex: CharIndex, mnp: MessageTextNbrPtr];
-- Clears the screen bit map and fixes the line blocks for all lines from [startLine ..
-- firstLineOffScreen].
Underline: PROCEDURE [start, end: CharIndex, underlineType: UnderlineType,
pendingDelete: BOOLEAN, mnp: MessageTextNbrPtr];
-- Draws an underline indication on the screen for the visible section of the message in
-- the range [start .. end).
DrawUnderlineInLine: PROCEDURE [start, end: ScreenXCoord, line: LinePtr,
underlineType: UnderlineType, pendingDelete: BOOLEAN];
-- XOR’s an underline from start to end on the last scan line for line.
DeUnderline: PROCEDURE [start, end: CharIndex, underlineType: UnderlineType,
pendingDelete: BOOLEAN, mnp: MessageTextNbrPtr];
-- Removes the underline indication on the screen for the visible section of the message
-- in the range [start .. end).
UnderlineSelection: PROCEDURE [selection: TextSelectionPtr, underline: UnderlineType];
-- Underlines entire selection.
DeUnderlineSelection: PROCEDURE
[selection: TextSelectionPtr, underline: UnderlineType];
-- DeUnderlines entire selection.
ClearSourceSelection: PROCEDURE [unlock: BOOLEAN ← TRUE];
-- DeUnderlines and reinitializes intC.source.
InitializeSelection: PROCEDURE [selection: TextSelectionPtr];
-- Initializes a selection to its default values.
FormatMessage: PROCEDURE [vm: vmD.VirtualMessagePtr];
-- Formats all of the composed message from the high water mark to the end,
-- expanding the message to break up long lines if necessary. highWaterMark is
-- set to the end of the message.
MapCharIndexToLine: PROCEDURE [index: CharIndex, mnp: MessageTextNbrPtr]
RETURNS [LinePtr];
-- Returns the screen line that contains index. Returns NIL if index is not currently
-- displayed on any visible screen line.
RangeRightXInLine: PROCEDURE [start, to: CharIndex, startX: ScreenXCoord,
message: vmD.VirtualMessagePtr] RETURNS [width: CARDINAL];
-- Returns the sum of the widths in screen raster points of the characters from the
-- interval [start .. to) in messsage if placed starting at startX.
MapCharIndexInLineToLeftX: PROCEDURE [index: CharIndex, line: LinePtr,
message: vmD.VirtualMessagePtr] RETURNS [x: ScreenXCoord];
-- index is in line.
-- Returns the ScreenXCoord of the left edge of the character corresponding to index in
-- message.
AdjustFirstCharIndices: PROCEDURE [firstLine: LinePtr, increment: INTEGER];
-- Increments the firstCharIndex of all screen lines from firstLine on.
MapCursorToCharIndex: PROCEDURE [x: ScreenXCoord, y: ScreenYCoord,
mnp: MessageTextNbrPtr] RETURNS [index: CharIndex];
-- Map x,y to a char index in message. If x,y is to the right of the rightmost char on its
-- line, treat as rightmost character. Similarly, if y is too far down on screen, treat as if
-- y was on the last screen line that holds normal message text.
NthLineFrom: PROCEDURE [line: LinePtr, n: CARDINAL] RETURNS [nthLine: LinePtr];
-- Returns the nth line from line in the line chain, or NIL if fewer than n lines remain.
-- Keyboard management procedures --
ShiftKey: PROCEDURE [state: KeyDefs.updown] RETURNS [yes: BOOLEAN];
ComKey: PROCEDURE [state: KeyDefs.updown] RETURNS [yes: BOOLEAN];
ControlKey: PROCEDURE [state: KeyDefs.updown] RETURNS [yes: BOOLEAN];
ComTap: PROCEDURE RETURNS [yes: BOOLEAN];
-- Returns TRUE iff a Com tap has occurred. Upon return of TRUE, Com tap is reset.
ControlTap: PROCEDURE RETURNS [yes: BOOLEAN];
-- Returns TRUE iff a Control tap has occurred. Upon return of TRUE, Control tap is
-- reset.
ResetTaps: PROCEDURE;
-- To be called when any mouse buttons go down in selection areas or on a
-- SHIFT-CANCEL.
MonitorTaps: PROCEDURE;
-- To be called continuously. Maintains Control and COM key states and records Com
-- and Control taps.
-- Buffer management procedures --
ResetInsertionBuffer: PROCEDURE [mnp: MessageTextNbrPtr];
-- Resets mnp.insertionBuffer to be empty.
ResetDeletionBuffer: PROCEDURE [mnp: MessageTextNbrPtr];
-- Resets mnp.deletionBuffer to be empty.
ResetBuffers: PROCEDURE [mnp: MessageTextNbrPtr];
-- Resets both mnp.insertionBufffer and mnp.deletionBuffer.
SwapMessageWithDeletionBuffer: PROCEDURE [mnp: MessageTextNbrPtr];
-- Exchanges contents of mnp.message with mnp.deletionBuffer.
SwapMessageWithInsertionBuffer: PROCEDURE [mnp: MessageTextNbrPtr];
-- Exchanges contents of mnp.message with mnp.insertionBuffer.
SwapInsertionWithDeletionBuffer: PROCEDURE [mnp: MessageTextNbrPtr];
-- Exchanges contents of mnp.insertionBuffer with mnp.deletionBuffer.
END. -- of Editor --