home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 9.9 KB | 245 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UTranscriptView.p }
- { Copyright © 1985-1990 Apple Computer, Inc. All rights reserved. }
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := FALSE}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT UTranscriptView;
- { This unit implements the debug window, called the "transcript view." TTranscriptView is not
- for the faint of heart, but it is possible to subclass it and override its methods, thereby
- customizing the debug window's behavior (but not the debugger's behaviour since the debugger
- USES a TTranscriptView). }
-
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED __UTranscriptView__}
- {$SETC __UTranscriptView__ := FALSE}
- {$ENDC}
-
- {$IFC NOT __UTranscriptView__}
- {$SETC __UTranscriptView__ := TRUE}
-
- { • Auto-Include the requirements for this unit's interface. }
- {$SETC UTranscriptViewIncludes := UsingIncludes}
- {$SETC UsingIncludes := TRUE}
- {$I+}
- {$IFC UNDEFINED __UMacApp__} {$I UMacApp.p} {$ENDC}
- {$SETC UsingIncludes := UTranscriptViewIncludes}
-
- CONST
- kHMargin = 4;
- kVMargin = 4;
- kWWEol = CHR($0D); { Character to consider the line break }
- kForceDepth = 10; { Maximum number of forceOption changes that
- will be remembered }
-
- TYPE
- WrForceOptions = (WrForceOn, WrForceOff, WrForceUnchanged); { corresponds to
- TrcForceOptions. See TTranscriptView.ForceOutput and .EndForce. }
-
- AText = PACKED ARRAY [0..10000] OF CHAR;
- TextPtr = ^AText;
- TextHandle = ^TextPtr; { Handy (get it? handy) way of referring to
- the stored text }
-
- ALineLens = ARRAY [0..10000] OF INTEGER; { Kinda like a brain damaged TE, we
- keep track of line lengths to aid
- in rendering }
- LineLensPtr = ^ALineLens;
- LineLensHandle = ^LineLensPtr;
-
- ForceState = RECORD { If toWindow is TRUE, output to the window.
- If toFile is TRUE, output to the redirect
- file. A stack of these is maintained by
- the TTranscriptView. }
- toWindow: BOOLEAN;
- toFile: BOOLEAN;
- END;
-
- TYPE
-
- TTranscriptView = OBJECT (TView) { C A U T I O N -- this object is not really
- for public consumption. Use it at your own
- risk! }
- fWrToWindow: BOOLEAN; { set to TRUE to enable writelns to window }
- fWrToFile: BOOLEAN; { set to TRUE to enable writelns to file }
- fCols: INTEGER; { Max characters per line }
- fRows: INTEGER; { Number of lines saved. After this number
- of lines is exceeded, the oldest lines
- start falling off. }
- fTotal: INTEGER; { number of characters in all lines together
- }
- fText: TextHandle; { the ring buffer: blanks pad each line to
- 80 chars }
- fLineLengths: LineLensHandle; { linelength of each line.
- fBufferLinesLens^^[0] is # of characters
- in the line that begins with fText^^[0] }
- fLineStarts: LineLensHandle; { offset into the fText handle of the first
- character in the line}
- fFirstLineIndex: INTEGER; { index where in the linelengths/starts
- array the top line starts }
-
- fTextStyle: TextStyle; { The style to with which to display the
- view }
- fFontInfo: FontInfo; { Font Info derived from the style }
- fFontHeight: INTEGER; { font height }
-
- fGotRefnum: BOOLEAN; { TRUE if there is a valid file refnum in
- fRefnum and fVRefNum. }
- fRefnum: INTEGER; { refnum for redirect output }
- fVRefNum: INTEGER; { vRefNum for redirected output. }
-
- fForceStack: ARRAY [1..kForceDepth] OF ForceState; { A stack of forced output
- states. ForceOutput and
- EndForce methods push
- and pop this stack,
- respectively. }
- fForcePtr: INTEGER; { Top of the stack in fForceStack. }
-
- fHelpProc: ProcPtr; { Call this to show help in response to the
- "Help" key. Default is no help. }
- fLastInsertionPointTime: Longint; { Last time InsertionPoint was on }
- fInsertionPointOn: BOOLEAN; { True if InsertionPoint was turned on by
- idle }
- fInsertionPt: Point; { location of the insertion pt in Row, col }
- fLastCh: CHAR; { last character typed }
- fUpdateRgn: RgnHandle; { used in scrolling shortcut }
-
- FUNCTION TTranscriptView.DoIdle(phase: IdlePhase): BOOLEAN; OVERRIDE;
- { Blinks the insertion point. }
-
- FUNCTION TTranscriptView.DoHelp(VAR info: EventInfo;
- VAR message: UNIV Longint): TCommand; OVERRIDE;
- { If fHelpis non-NIL, it is called. Called in response to a "Help" keypress. }
-
- FUNCTION TTranscriptView.DoKeyCommand(ch: CHAR;
- aKeyCode: INTEGER;
- VAR info: EventInfo): TCommand; OVERRIDE;
- { Handles return, enter, arrows, home, end, and help keys only - they all perform the
- natural scrolling actions. Sets fLastCh to ch. }
-
- PROCEDURE TTranscriptView.Draw(area: Rect); OVERRIDE;
- { Draws the visible portion of the stored text. }
-
- PROCEDURE TTranscriptView.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this classes
- fields. }
-
- PROCEDURE TTranscriptView.Free; OVERRIDE;
- { Frees the text buffers before freeing SELF. Turns off output redirection if it is
- on. }
-
- FUNCTION TTranscriptView.HandleMouseDown(theMouse: VPoint;
- VAR info: EventInfo;
- VAR hysteresis: Point;
- VAR theCommand: TCommand): BOOLEAN;
- OVERRIDE;
- { Calls INHERITED HandleMouseDown. }
-
- { TranscriptWindow Specific methods }
- PROCEDURE TTranscriptView.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
- { Calls INHERITED IRes, SELF.CommonInit, then sets the view size to the correct size
- for the line width. }
-
- PROCEDURE TTranscriptView.AddText(textBuf: Ptr;
- byteCount: INTEGER);
- { If fWrToWindow is currently TRUE, inserts the text in textBuf at the current
- insertion point. If fWrToFile is true, calls SELF.AddTextToFile to append textBuf
- to the redirect file. Can handle backspace characters and multiple line feeds in
- textBuf. }
-
- PROCEDURE TTranscriptView.AddTextToFile(textBuf: Ptr;
- byteCount: INTEGER);
- { Appends the text in textBuf to the file fRefNum. }
-
- PROCEDURE TTranscriptView.RevealInsertionPoint;
- { Scrolls the insertion point into view. }
-
- PROCEDURE TTranscriptView.EndForce;
- { Sets fWrToWindow and fWrToFile to their prior states by popping the old states off
- the fForceStack stack. }
-
- PROCEDURE TTranscriptView.ForceOutput(wrToWindow, wrToFile: WrForceOptions);
- { Pushes the current states of fWrToWindow and fWrToFile onto the fForceStack stack,
- then sets them according to the arguments. If wrToWindow is not WrForceUnchanged,
- fWrToWindow is set to the boolean value of "wrToWindow = WrForceOn"; otherwise
- fWrToWindow is left unchanged. Likewise for wrToFile and fWrToFile. }
-
- FUNCTION TTranscriptView.GetInsertionPointRect: Rect;
- { Returns the rectangle which defines the insertion point. }
-
- PROCEDURE TTranscriptView.CommonInit(itsSuperView: TView;
- outputFont, outputSize: INTEGER;
- numLines, numCharsPerLine: INTEGER);
- { Performs general initialization of the view according to the arguments given. }
-
- PROCEDURE TTranscriptView.ITranscriptView(itsSuperView: TView;
- outputFont, outputSize: INTEGER;
- numLines, numCharsPerLine: INTEGER);
- { Calls IView, then CommonInit, then sets the view size to the correct dimensions for
- the line width. }
-
- FUNCTION TTranscriptView.PrevIndex(ln: INTEGER): INTEGER;
- { Returns the index into the line buffers for the line immediately preceeding ln,
- wrapping backwards if necessary. }
-
- FUNCTION TTranscriptView.SuccIndex(ln: INTEGER): INTEGER;
- { Returns the index into the line buffers for the line immediately succeeding ln,
- wrapping to 0 if necessary. }
-
- FUNCTION TTranscriptView.IndexToRow(index: INTEGER): INTEGER;
- { Converts index from an index into the line buffers into a relative line number in
- the output. }
-
- FUNCTION TTranscriptView.RowToIndex(row: INTEGER): INTEGER;
- { Converts the output line number row into its index into the line buffers. }
-
- FUNCTION TTranscriptView.IndexToLocal(index: INTEGER): INTEGER;
- { Converts an index into the line buffers into a vertical local drawing coordinate in
- the view. }
-
- PROCEDURE TTranscriptView.InstallTextStyle(theStyle: TextStyle);
- { Makes theStyle the text style for the view, resizing as necessary. }
-
- FUNCTION TTranscriptView.LocalToIndex(local: INTEGER): INTEGER;
- { Converts a vertical local drawing coordinate in the view into an index into the
- line buffers. }
-
- FUNCTION TTranscriptView.IndexColToLocal(index, col: INTEGER): Point;
- { Converts an index into the line buffers and a column number into local drawing
- coordinates. }
-
- FUNCTION TTranscriptView.LocalToCol(local: INTEGER): INTEGER;
- { Converts a horizontal drawing coordinate into a column number. }
-
- FUNCTION TTranscriptView.Redirect(vRefnum: INTEGER;
- fileName: StringPtr): OSErr;
- { Opens the given file for the purpose of redirecting output. If fileName contains
- '>>', the file is opened for append; otherwise, it is truncated to zero length
- first. Does not set the fWrToFile state variable. }
-
- PROCEDURE TTranscriptView.Scroll(howManyLines: INTEGER);
- { Scrolls the view by howManyLines lines. }
-
- PROCEDURE TTranscriptView.RevealInsertionPointLine;
- { Scrolls the insertion point into view. }
- END;
-
- PROCEDURE IDUTranscriptView;
- { Displays the compile date and time of this unit. }
-
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-