home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Interfaces / PInterfaces / UTranscriptView.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  9.9 KB  |  245 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2. { UTranscriptView.p }
  3. { Copyright © 1985-1990 Apple Computer, Inc. All rights reserved. }
  4.  
  5. {$IFC UNDEFINED UsingIncludes}
  6. {$SETC UsingIncludes := FALSE}
  7. {$ENDC}
  8.  
  9. {$IFC NOT UsingIncludes}
  10. UNIT UTranscriptView;
  11.         { This unit implements the debug window, called the "transcript view." TTranscriptView is not
  12.         for the faint of heart, but it is possible to subclass it and override its methods, thereby
  13.         customizing the debug window's behavior (but not the debugger's behaviour since the debugger
  14.         USES a TTranscriptView). }
  15.  
  16.     INTERFACE
  17.         {$ENDC}
  18.  
  19.         {$IFC UNDEFINED __UTranscriptView__}
  20.         {$SETC __UTranscriptView__ := FALSE}
  21.         {$ENDC}
  22.  
  23.         {$IFC NOT __UTranscriptView__}
  24.         {$SETC __UTranscriptView__ := TRUE}
  25.  
  26.         { • Auto-Include the requirements for this unit's interface. }
  27.         {$SETC UTranscriptViewIncludes := UsingIncludes}
  28.         {$SETC UsingIncludes := TRUE}
  29.         {$I+}
  30.         {$IFC UNDEFINED __UMacApp__} {$I UMacApp.p} {$ENDC}
  31.         {$SETC UsingIncludes := UTranscriptViewIncludes}
  32.  
  33.         CONST
  34.             kHMargin            = 4;
  35.             kVMargin            = 4;
  36.             kWWEol                = CHR($0D);             { Character to consider the line break }
  37.             kForceDepth         = 10;                    { Maximum number of forceOption changes that
  38.                                                          will be remembered }
  39.  
  40.         TYPE
  41.             WrForceOptions        = (WrForceOn, WrForceOff, WrForceUnchanged); { corresponds to
  42.                 TrcForceOptions. See TTranscriptView.ForceOutput and .EndForce. }
  43.  
  44.             AText                = PACKED ARRAY [0..10000] OF CHAR;
  45.             TextPtr             = ^AText;
  46.             TextHandle            = ^TextPtr;             { Handy (get it? handy) way of referring to
  47.                                                          the stored text }
  48.  
  49.             ALineLens            = ARRAY [0..10000] OF INTEGER; { Kinda like a brain damaged TE, we
  50.                                                                 keep track of line lengths to aid
  51.                                                                 in rendering }
  52.             LineLensPtr         = ^ALineLens;
  53.             LineLensHandle        = ^LineLensPtr;
  54.  
  55.             ForceState            = RECORD                { If toWindow is TRUE, output to the window.
  56.                                                          If toFile is TRUE, output to the redirect
  57.                                                          file. A stack of these is maintained by
  58.                                                          the TTranscriptView. }
  59.                 toWindow:            BOOLEAN;
  60.                 toFile:             BOOLEAN;
  61.                 END;
  62.  
  63.         TYPE
  64.  
  65.             TTranscriptView     = OBJECT (TView)        { C A U T I O N -- this object is not really
  66.                                                          for public consumption. Use it at your own
  67.                                                          risk! }
  68.                 fWrToWindow:        BOOLEAN;            { set to TRUE to enable writelns to window }
  69.                 fWrToFile:            BOOLEAN;            { set to TRUE to enable writelns to file }
  70.                 fCols:                INTEGER;            { Max characters per line }
  71.                 fRows:                INTEGER;            { Number of lines saved. After this number
  72.                                                          of lines is exceeded, the oldest lines
  73.                                                          start falling off. }
  74.                 fTotal:             INTEGER;            { number of characters in all lines together
  75.                                                          }
  76.                 fText:                TextHandle;         { the ring buffer: blanks pad each line to
  77.                                                          80 chars }
  78.                 fLineLengths:        LineLensHandle;     { linelength of each line.
  79.                                                          fBufferLinesLens^^[0] is # of characters
  80.                                                          in the line that begins with fText^^[0] }
  81.                 fLineStarts:        LineLensHandle;     { offset into the fText handle of the first
  82.                                                          character in the line}
  83.                 fFirstLineIndex:    INTEGER;            { index where in the linelengths/starts
  84.                                                          array the top line starts }
  85.  
  86.                 fTextStyle:         TextStyle;            { The style to with which to display the
  87.                                                          view }
  88.                 fFontInfo:            FontInfo;            { Font Info derived from the style }
  89.                 fFontHeight:        INTEGER;            { font height }
  90.  
  91.                 fGotRefnum:         BOOLEAN;            { TRUE if there is a valid file refnum in
  92.                                                          fRefnum and fVRefNum. }
  93.                 fRefnum:            INTEGER;            { refnum for redirect output }
  94.                 fVRefNum:            INTEGER;            { vRefNum for redirected output. }
  95.  
  96.                 fForceStack:        ARRAY [1..kForceDepth] OF ForceState; { A stack of forced output
  97.                                                                            states. ForceOutput and
  98.                                                                            EndForce methods push
  99.                                                                            and pop this stack,
  100.                                                                            respectively. }
  101.                 fForcePtr:            INTEGER;            { Top of the stack in fForceStack. }
  102.  
  103.                 fHelpProc:            ProcPtr;            { Call this to show help in response to the
  104.                                                          "Help" key. Default is no help. }
  105.                 fLastInsertionPointTime: Longint;        { Last time InsertionPoint was on }
  106.                 fInsertionPointOn:    BOOLEAN;            { True if InsertionPoint was turned on by
  107.                                                          idle }
  108.                 fInsertionPt:        Point;                { location of the insertion pt in Row, col }
  109.                 fLastCh:            CHAR;                { last character typed }
  110.                 fUpdateRgn:         RgnHandle;            { used in scrolling shortcut }
  111.  
  112.                 FUNCTION TTranscriptView.DoIdle(phase: IdlePhase): BOOLEAN; OVERRIDE;
  113.                 { Blinks the insertion point. }
  114.  
  115.                 FUNCTION TTranscriptView.DoHelp(VAR info: EventInfo;
  116.                                                 VAR message: UNIV Longint): TCommand; OVERRIDE;
  117.                 { If fHelpis non-NIL, it is called. Called in response to a "Help" keypress. }
  118.  
  119.                 FUNCTION TTranscriptView.DoKeyCommand(ch: CHAR;
  120.                                                       aKeyCode: INTEGER;
  121.                                                       VAR info: EventInfo): TCommand; OVERRIDE;
  122.                 { Handles return, enter, arrows, home, end, and help keys only - they all perform the
  123.                 natural scrolling actions. Sets fLastCh to ch. }
  124.  
  125.                 PROCEDURE TTranscriptView.Draw(area: Rect); OVERRIDE;
  126.                 { Draws the visible portion of the stored text. }
  127.  
  128.                 PROCEDURE TTranscriptView.Fields(PROCEDURE
  129.                                                  DoToField(fieldName: Str255;
  130.                                                            fieldAddr: Ptr;
  131.                                                            fieldType: INTEGER)); OVERRIDE;
  132.                 { Used by the Inspector and the Debugger to display the contents of this classes
  133.                 fields. }
  134.  
  135.                 PROCEDURE TTranscriptView.Free; OVERRIDE;
  136.                 { Frees the text buffers before freeing SELF. Turns off output redirection if it is
  137.                 on. }
  138.  
  139.                 FUNCTION TTranscriptView.HandleMouseDown(theMouse: VPoint;
  140.                                                          VAR info: EventInfo;
  141.                                                          VAR hysteresis: Point;
  142.                                                          VAR theCommand: TCommand): BOOLEAN;
  143.                     OVERRIDE;
  144.                 { Calls INHERITED HandleMouseDown. }
  145.  
  146.                 { TranscriptWindow Specific methods }
  147.                 PROCEDURE TTranscriptView.IRes(itsDocument: TDocument;
  148.                                                itsSuperView: TView;
  149.                                                VAR itsParams: Ptr); OVERRIDE;
  150.                 { Calls INHERITED IRes, SELF.CommonInit, then sets the view size to the correct size
  151.                 for the line width. }
  152.  
  153.                 PROCEDURE TTranscriptView.AddText(textBuf: Ptr;
  154.                                                   byteCount: INTEGER);
  155.                 { If fWrToWindow is currently TRUE, inserts the text in textBuf at the current
  156.                 insertion point. If fWrToFile is true, calls SELF.AddTextToFile to append textBuf
  157.                 to the redirect file. Can handle backspace characters and multiple line feeds in
  158.                 textBuf. }
  159.  
  160.                 PROCEDURE TTranscriptView.AddTextToFile(textBuf: Ptr;
  161.                                                         byteCount: INTEGER);
  162.                 { Appends the text in textBuf to the file fRefNum. }
  163.  
  164.                 PROCEDURE TTranscriptView.RevealInsertionPoint;
  165.                 { Scrolls the insertion point into view. }
  166.  
  167.                 PROCEDURE TTranscriptView.EndForce;
  168.                 { Sets fWrToWindow and fWrToFile to their prior states by popping the old states off
  169.                 the fForceStack stack. }
  170.  
  171.                 PROCEDURE TTranscriptView.ForceOutput(wrToWindow, wrToFile: WrForceOptions);
  172.                 { Pushes the current states of fWrToWindow and fWrToFile onto the fForceStack stack,
  173.                 then sets them according to the arguments. If wrToWindow is not WrForceUnchanged,
  174.                 fWrToWindow is set to the boolean value of "wrToWindow = WrForceOn"; otherwise
  175.                 fWrToWindow is left unchanged. Likewise for wrToFile and fWrToFile. }
  176.  
  177.                 FUNCTION TTranscriptView.GetInsertionPointRect: Rect;
  178.                 { Returns the rectangle which defines the insertion point. }
  179.  
  180.                 PROCEDURE TTranscriptView.CommonInit(itsSuperView: TView;
  181.                                                      outputFont, outputSize: INTEGER;
  182.                                                      numLines, numCharsPerLine: INTEGER);
  183.                 { Performs general initialization of the view according to the arguments given. }
  184.  
  185.                 PROCEDURE TTranscriptView.ITranscriptView(itsSuperView: TView;
  186.                                                           outputFont, outputSize: INTEGER;
  187.                                                           numLines, numCharsPerLine: INTEGER);
  188.                 { Calls IView, then CommonInit, then sets the view size to the correct dimensions for
  189.                 the line width. }
  190.  
  191.                 FUNCTION TTranscriptView.PrevIndex(ln: INTEGER): INTEGER;
  192.                 { Returns the index into the line buffers for the line immediately preceeding ln,
  193.                 wrapping backwards if necessary. }
  194.  
  195.                 FUNCTION TTranscriptView.SuccIndex(ln: INTEGER): INTEGER;
  196.                 { Returns the index into the line buffers for the line immediately succeeding ln,
  197.                 wrapping to 0 if necessary. }
  198.  
  199.                 FUNCTION TTranscriptView.IndexToRow(index: INTEGER): INTEGER;
  200.                 { Converts index from an index into the line buffers into a relative line number in
  201.                 the output. }
  202.  
  203.                 FUNCTION TTranscriptView.RowToIndex(row: INTEGER): INTEGER;
  204.                 { Converts the output line number row into its index into the line buffers. }
  205.  
  206.                 FUNCTION TTranscriptView.IndexToLocal(index: INTEGER): INTEGER;
  207.                 { Converts an index into the line buffers into a vertical local drawing coordinate in
  208.                 the view. }
  209.  
  210.                 PROCEDURE TTranscriptView.InstallTextStyle(theStyle: TextStyle);
  211.                 { Makes theStyle the text style for the view, resizing as necessary. }
  212.  
  213.                 FUNCTION TTranscriptView.LocalToIndex(local: INTEGER): INTEGER;
  214.                 { Converts a vertical local drawing coordinate in the view into an index into the
  215.                 line buffers. }
  216.  
  217.                 FUNCTION TTranscriptView.IndexColToLocal(index, col: INTEGER): Point;
  218.                 { Converts an index into the line buffers and a column number into local drawing
  219.                 coordinates. }
  220.  
  221.                 FUNCTION TTranscriptView.LocalToCol(local: INTEGER): INTEGER;
  222.                 { Converts a horizontal drawing coordinate into a column number. }
  223.  
  224.                 FUNCTION TTranscriptView.Redirect(vRefnum: INTEGER;
  225.                                                   fileName: StringPtr): OSErr;
  226.                 { Opens the given file for the purpose of redirecting output. If fileName contains
  227.                 '>>', the file is opened for append; otherwise, it is truncated to zero length
  228.                 first. Does not set the fWrToFile state variable. }
  229.  
  230.                 PROCEDURE TTranscriptView.Scroll(howManyLines: INTEGER);
  231.                 { Scrolls the view by howManyLines lines. }
  232.  
  233.                 PROCEDURE TTranscriptView.RevealInsertionPointLine;
  234.                 { Scrolls the insertion point into view. }
  235.                 END;
  236.  
  237.         PROCEDURE IDUTranscriptView;
  238.         { Displays the compile date and time of this unit. }
  239.  
  240.         {$ENDC}
  241.  
  242.         {$IFC NOT UsingIncludes}
  243. END.
  244. {$ENDC}
  245.